0

表错误

( http://imgur.com/2Ev8u4L )

正如您从图像中看到的那样,表中的第一行仅在实际表中。我不确定可能是代码错误?

$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>";
}
4

1 回答 1

1

你不检查,如果$selectNews真的有效。从PDO::query

返回值
PDO::query()返回一个 PDOStatement 对象,如果失败则返回FALSE

更新:

您已将tbodyandtable放入您的 while 循环中。您必须将开始和结束标签放在外面

echo "<tbody>";
while ($results = $selectNews->fetch(PDO::FETCH_ASSOC)) {
    echo "<tr><td>";
    ...
    echo $results['Creater']."</td></tr>";
}

echo "</tbody>";
echo "</table>";
于 2013-11-06T22:15:09.967 回答