从图像中可以看出,表中的第一行仅在实际表中。可能是代码错误,我不确定?
$selectNews = $PDO->query("SELECT * FROM `news`");
echo '<table class="table">';
echo '<thead>';
echo '<th>Update Number</th>';
echo '<th>Title</th>';
echo '<th>Description</th>';
echo '<th>Created On</th>';
echo '<th>Created By</th>';
echo '</thead>';
while ($results = $selectNews->fetch(PDO::FETCH_ASSOC)) {
echo "<tbody>";
echo "<tr><td>";
echo $results['ID']."</td><td>";
echo $results['Title']."</td><td>";
echo $results['Description']."</td><td>";
echo date('d/m/Y g:i:s A', strtotime($results['Time']))."</td><td>";
echo $results['Creater']."</td></tr>";
echo "</tbody>";
echo "</table>";
}
答案 0 :(得分:1)
如果$selectNews
确实有效,则不检查。来自PDO::query
返回值
PDO :: query()会在失败时返回PDOStatement对象,或 FALSE 。
更新
您已将tbody
和table
放入while循环中。您必须将开始和结束标记放在
echo "<tbody>";
while ($results = $selectNews->fetch(PDO::FETCH_ASSOC)) {
echo "<tr><td>";
...
echo $results['Creater']."</td></tr>";
}
echo "</tbody>";
echo "</table>";