gpt4 book ai didi

php - 内连接只从mysql中选择两条记录

转载 作者:行者123 更新时间:2023-11-29 23:45:39 24 4
gpt4 key购买 nike

我有一个主题和一个部门表,每个主题都与部门表关联。我正在尝试选择所有主题,包括部门名称。下面的代码工作完美,但只显示两条记录。任何帮助将不胜感激

//Select statement
$selects=$connection->query("SELECT
subjects.id
, subjects.name
, subjects.related_to
, subjects.related_to_sem
, departments.dept
FROM subjects
INNER JOIN departments
ON subjects.related_to = departments.dep_id");

<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th>Sub Id</th>
<th>Subject Name</th>
<th>Related to Department</th>
<th>Related to Semester</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
while($result=$select->fetch_assoc()) {
?>
<tr>
<td><?php echo $result['id']; ?></td>
<td class="center"><?php echo $result['name']; ?></td>
<td class="center"><?php echo $result['dept']; ?></td>
<td class="center"><?php echo $result['related_to_sem']; ?></td>
<td class="center">
<a class="btn btn-info" href="#">
<i class="icon-edit icon-white"></i>
Edit
</a>
<a class="btn btn-danger" href="#">
<i class="icon-trash icon-white"></i>
Delete
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>

最佳答案

select 

subjects.id,subjects.name,
subjects.related_to,
subjects.related_to_sem,
departments.dept

from

subjects

LEFT OUTER JOIN departments ON subjects.id=departments.dep_id

关于php - 内连接只从mysql中选择两条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25968078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com