【发布时间】:2014-06-21 03:44:52
【问题描述】:
我的 PHP while 语句有问题。它是:
$row = mysqli_fetch_array($result);
$time_in_12_hour_format = date("g:i a", strtotime($row['Time']));
while($row = mysqli_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['Name'] . "</td><td>" . $row['Description'] . "</td><td>" . $row['Date'] . " at " . $time_in_12_hour_format . "</td><td>" . $row['Location'] . "</td>"; //$row['index'] the index here is a field name
是的,我确实意识到我定义了两次 $row,但我不确定如何更改它。如果我从 while 语句中删除 $row = mysqli_fetch_array($result) ,页面将不会加载并返回错误。到目前为止,页面加载但表格是空的,即使我知道在我添加军事时间转换器之前表格中显示了一条记录。任何帮助表示赞赏。
【问题讨论】:
-
先删除
$row = mysqli_fetch_array($result);,然后将$time_in_12_hour_format = date("g:i a", strtotime($row['Time']));添加到循环中。
标签: php mysql sql loops while-loop