我希望使用PHP在表中显示来自单个人的多个记录,但是其他记录在表外,并且表中只有一个记录。它看起来像(view me)。
这是我的代码
$resultSet2 = $mysqli->query("SELECT class_subject, target_grade, current_grade , cl.classID FROM students AS stud INNER JOIN grade AS gr ON stud.studentID = gr.studentID INNER JOIN class cl ON gr.classID = cl.classID WHERE (cl.classID = '1' OR '2') and surname = '$search' ");
和
while($row = $resultSet2->fetch_array()) {
echo "<tr>";
echo "<td>" . $row['class_subject'] . "</td>";
echo "<td>" . $row['target_grade'] . "</td>";
echo "<td>" . $row['current_grade'] . "</td>";
echo "</tr>";
echo "</table>";
我怎样才能像第一个一样把它们放在桌子里?
答案 0 :(得分:3)
将结束表格标签移到while循环</table>
之外,同时关闭while循环。
echo "<table>";
while($row = $resultSet2->fetch_array()) {
echo "<tr>";
echo "<td>" . $row['class_subject'] . "</td>";
echo "<td>" . $row['target_grade'] . "</td>";
echo "<td>" . $row['current_grade'] . "</td>";
echo "</tr>";
}
echo "</table>";