Why is my while loop only returning one value from the database?
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">
<开发者_StackOverflowul>
<?
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>
My guess is that you're using mysql_fetch_array, but then referencing the element as though it were an associative array. Try using one of the following:
mysql_fetch_array($upcomingdates, MYSQL_ASSOC)
or
mysql_fetch_assoc($upcomingdates)
Dropped the table in the database and re-inserted it and everything was working again! I guess something went wrong the first time I imported it.
精彩评论