{将2张桌子连在一起(带有老师ID和老师姓名)
我创建了联接,并在SQL中进行了测试。看起来不错。我正在尝试在屏幕上打印它。
$classandteacher = "SELECT person_name FROM people RIGHT OUTER JOIN classes ON classes.instructor_id=people.instructor_id ASC";
$result = mysqli_query($dbc, $classandteacher){
while($row = mysqli_query($dbc, $result));
$teacher = $row["person_name"];
echo ("Teacher: " . $teacher . "<br>");}
最佳答案
这是因为While循环的格式不正确。
删除;
并将其放入{}
您还需要使用mysqli_fetch_assoc($result)
从查询中获取Array
$classandteacher = "SELECT person_name FROM people RIGHT OUTER JOIN classes ON classes.instructor_id=people.instructor_id ASC";
$result = mysqli_query($dbc, $classandteacher);
if(!$result) { //If your MYSQL query is throwing an error
error_log(mysqli_error());
}
while($row = mysqli_fetch_assoc($result))
{
$teacher = $row["person_name"];
echo "Teacher: " . $teacher . "<br>";
}
关于php - 从表联接获取我的信息以在PHP中显示时出现问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41647547/