我试图将数据库中的一些数据显示到html表中。我的其他查询工作正常,我能够检索一些其他表并将其显示到我的网站,虽然这个特定的查询甚至没有,如果有一个函数mysqli_error()。我尝试直接从我的数据库(phpmyadmin)执行查询,它检索它就好了。
这是我的代码。
注意:$ p_id变量有一些数据是' 3'。
PHP
$p_sql = "SELECT p.package_name, p.package_price, p.package_details, p.package_categories, p.package_id FROM event_table as e inner join package as p on e.package_id = p.package_id where e.package_id = '$p_id' group by e.package_id";
$data_p = mysqli_query($conn, $p_sql) ;
$result = mysqli_fetch_assoc($data_p);
$p_amount = $result['package_price'];
while ($record_p = mysqli_fetch_array($data_p)) {
echo "<table border = 1>";
echo "<tr>";
echo "<th>" . "Package Name" . "</th>";
echo "<th>" . "Package Price" . "</th>";
echo "<th>" . "Package Details" . "</th>";
echo "<th>" . "Package Categories" . "</th>";
echo "</tr>";
echo "<tr>";
echo "<td>" . "<br />" . $record_p['package_name'] . "<br />" . "</td>" ;
echo "<td>" . "<br />" . $record_p['package_price'] . "<br />" . "</td>" ;
echo "<td>" . "<br />" . $record_p['package_details'] . "<br />" . "</td>" ;
echo "<td>" . "<br />" . $record_p['package_categories'] . "<br />" . "</td>" ;
echo "<tr/>";
}
echo "</table>";
if(!$data_p){
echo("Error description: " . mysqli_error($conn));
}