我想把整個SQL數據庫放到html表中。我正在使用MySQLi API。 但它只是返回表的第一行,其餘的人只是看亂七八糟up.Here是我的代碼:把整個SQL數據庫放到HTML表中
<h1> School Lesson System</h1>
<?php
if(isset($_SESSION['u_id'])) {
echo "You are logged in \n";
}
?>
<table border="1">
<thead>
<tr>
<td>Lesson_id</td>
<td>Teacher</td>
<td>Lesson</td>
<td>Day</td>
<td>Time</td>
<td>Classroom</td>
<td>Year</td>
<td>Curriculum</td>
</tr>
</thead>
<tbody>
<?php
require_once 'includes/dbh.inc.php';
$query = "SELECT * FROM monday";
$result = $conn->query($query);
$rows = $result->num_rows;
for ($j = 0; $j < $rows; ++$j) {
$result->data_seek($j);
$row = $result->fetch_array(MYSQLI_ASSOC);
echo "<tr>";
echo "<td>" . $row['Lesson_id']. "</td>";
echo "<td>". $row['Teacher']. "</td>";
echo "<td>" .$row['Lesson']. "</td>";
echo "<td>" . $row['Day']. "</td>";
echo "<td>". $row['Time']. "</td>";
echo "<td>". $row['Classroom']. "</td>";
echo "<td>". $row['Year']. "</td>";
echo "<td>". $row['Curriculum']. "</td>";
echo "</tr>";
echo"</tbody>";
echo"</table>";
}
include_once 'footer.php';
?>
這個任何解決方案????
而是用'for'循環的,只是做',而($行= $ result-> FETCH_ASSOC()){',這是標準的方式獲取行。 – Qirel
你有一個叫做'monday'的表?恐怕你有更大的問題需要解決! – Strawberry