我想要抓住外键,因为我需要将它用于画廊,每个上传的图像都分配给摄影师,这些摄影师也需要在菜单中显示。
我跟着this guide,一切顺利。我现在需要用PHP输出数据 - 这是我无法弄清楚的。
<?php
$sql = "SELECT * FROM borrowed WHERE employee.id = 'Reck' JOIN employee ON employee.id = borrowed.employeeid";
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result)) {
?>
<? echo $row['lastname']; ?>
<?php
}
?>
我收到错误警告:mysqli_fetch_array()要求参数1为mysqli_result,第12行/Applications/MAMP/htdocs/galleri/test.php中给出布尔值
第12行是while循环。
答案 0 :(得分:0)
您的查询中的错误请参阅查询结构How to use joins
在您的查询中,join
在where
条件之后,但必须在where
之前。它应该是这样的
$sql = "SELECT * FROM borrowed JOIN employee ON employee.id = borrowed.employeeid WHERE employee.id = 'Reck'";
和你的代码
<?php
$sql = "SELECT * FROM borrowed JOIN employee ON employee.id = borrowed.employeeid WHERE employee.id = 'Reck'";
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result)) {
echo $row['lastname'];
}
?>