$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>
确定查询返回多个值吗? – 2011-04-22 15:49:57
它正在工作,但现在它只返回一件事。我现在在数据库中有三件事。你有没有其他办法可以做到这一点?我不知道如何把它变成一个foreach循环 – Montez 2011-04-22 15:54:02
嗯,代码看起来好像到目前为止。你知道你的查询中有'LIMIT 1'吗? – 2011-04-22 15:57:53