我想显示或获取老师的名字,但它总是只获取老师的 id,谢谢你的帮助。这是我的代码: <?php include('../dbcon.php'); $query=mysqli_query($connection,"select * from `teacher_class`"); while($row=mysqli_fetch_array($query)){ ?> <tr> <td><?php echo $row['class_id']; ?></td> <td><?php echo $row['school_year']; ?></td> <td><?php echo $row['teacher_id']; ?></td> <td><?php echo $row['subject_id']; ?></td>这是数据库上的教师班级表这里是教师桌和分配教师表 分配教师表
2 回答
墨色风雨
TA贡献1853条经验 获得超6个赞
如果您要显示来自多个表的值,则需要连接这些表,然后只有您可以显示它们。
请阅读https://www.w3schools.com/sql/sql_join.asp以了解 SQL JOINS。
试试下面的代码。
$query=mysqli_query($connection,"SELECT * FROM 'teacher' AS teacher INNER JOIN teacher_class ON teacher.teacher_id = teacher_class.teacher_id");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['class_id']; ?></td>
<td><?php echo $row['school_year']; ?></td>
<td><?php echo $row['firstname'].' '.$row['mname'].' '.$row['lastname']; ?></td>
<td><?php echo $row['subject_id']; ?></td>
偶然的你
TA贡献1841条经验 获得超3个赞
这是您想要的查询
SELECT tc.teacher_id, t.teacher_name, tc.subject_id FROM teacher_class AS tc LEFT JOIN teacher ON t.teacher_id = tc.teacher_id
- 2 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消