Bootstrap表只显示一行

时间:2013-11-06 22:09:52

标签: php html mysql sql twitter-bootstrap

Table Error

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

1 个答案:

答案 0 :(得分:1)

如果$selectNews确实有效,则不检查。来自PDO::query

  

返回值
   PDO :: query()会在失败时返回PDOStatement对象,或 FALSE

更新

您已将tbodytable放入while循环中。您必须将开始和结束标记放在

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

echo "</tbody>";
echo "</table>";