问题描述
我一直在学习一些教程并创建了以下准备好的语句,但是它在我的网站上不起作用。我正在尝试使用会话变量来显示 2 个表中的数据。
$db_id = $_SESSION['customerID'];
$query = "SELECT * FROM booked_activities INNER JOIN activities ON booked_activities.activityID = activities.activityID WHERE booked_activities.customerID=?";
$stmt = MysqLi_stmt_init($connection);
//prepare the prepared statement
if(!MysqLi_stmt_prepare($stmt,$query)){
echo "sql statement Failed";
} else {
//bind parameters to the placeholders
MysqLi_stmt_bind_param($stmt,"i",$db_id);
//run parameters inside database
MysqLi_stmt_execute($stmt);
$result = MysqLi_stmt_get_result($stmt);
echo "<table border='1'>
<tr>
<th>Activity</th>
<th>Date</th>
<th>Tickets</th>
</tr>";
while($row = MysqLi_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['activity_name'] . "</td>";
echo "<td>" . $row['date_of_activity'] . "</td>";
echo "<td>" . $row['number_of_tickets'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
有人能发现我的代码有什么问题吗?我需要使用 $db_id 作为它在两个表中的公共字段。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)