为什么我的while循环只返回数据库中的一个值?

时间:2011-04-22 15:48:18

标签: php mysql html

PHP

$nextday = mysql_query("SELECT * FROM Tour_Dates WHERE DATEDIFF( tourDate, NOW() ) > 0 ORDER BY tourDate LIMIT 1")or die(mysql_error());
$upcomingdates = mysql_query("SELECT * FROM Tour_Dates WHERE DATEDIFF( tourDate, NOW() ) > 0 ORDER BY tourDate")or die(mysql_error());
$passeddates = mysql_query("SELECT * FROM Tour_Dates WHERE DATEDIFF( tourDate, NOW() ) < 0 ORDER BY tourDate")or die(mysql_error());

HTML

<label class="next-day"><? while($row = mysql_fetch_array($nextday)){echo $row['city'] ."  |  " .date("m.d.Y",strtotime($row['tourDate']));} ?></label>

<div class="upcoming">
<ul>
<?
while($row = mysql_fetch_array($upcomingdates))
{
echo '<li><span class="li-date">'. date("m.d.Y",strtotime($row['tourDate'])) .'</span><span class="li-address">' . $row['address'] . '</span><span class="li-city">' . $row['city'] . '</span><span class="li-time">' . date("g.i A",strtotime($row['tourTime'])).'</span></li>';
}
?>
</ul>
</div>
<div class="passed">
<ul>
<?
while($row = mysql_fetch_array($passeddates))
{
echo '<li><span class="li-date">'. date("m.d.Y",strtotime($row['tourDate'])) .'</span><span class="li-address">' . $row['address'] . '</span><span class="li-city">' . $row['city'] . '</span><span class="li-time">' . date("g.i A",strtotime($row['tourTime'])).'</span></li>';
}
?>
</ul>
</div>

2 个答案:

答案 0 :(得分:0)

我的猜测是你正在使用mysql_fetch_array,但随后引用该元素就好像它是一个关联数组。请尝试使用以下方法之一:

mysql_fetch_array($upcomingdates, MYSQL_ASSOC)

mysql_fetch_assoc($upcomingdates)

答案 1 :(得分:0)

删除数据库中的表并重新插入,一切都恢复正常!我猜第一次导入它时出了点问题。