是否可以使用mysql運行只有一個查詢mysql,然後做兩個不同的結果while循環。我如何做2 PHP的while循環與1 MySQL的查詢?
//this is the query
$qry_offers = mysql_query("SELECT * FROM offers ORDER BY offer_end ASC");
在第一回路
,我要顯示其具有「END_DATE」少或在第二循環中比今天
<div id="current">
<?
while($row_offers = mysql_fetch_assoc($qry_offers)) {
if ((date("Y-m-d H:i:s")) <= ($row_offers['offer_end'])) {
echo '<li><a href="#">'.$row_offers['offer_name'].'</a></li>';
}
}
?>
</div><!-- END OF CURRENT -->
等於任何結果,我要顯示具有任何結果一個 「end_date之間的」 大於今天
//this is where i would have the 2n while loop
<div id="inactive">
<?
while($row_offers = mysql_fetch_assoc($qry_offers)) {
if ((date("Y-m-d H:i:s")) > ($row_offers['offer_end'])) {
echo '<li><a href="#">'.$row_offers['offer_name'].'</a></li>';
}
}
?>
</div><!-- END OF INACTIVE -->
你試過了嗎?什麼不是這個工作? – bretterer
@bretterer:是的,我試過了,我只得到第一個循環的結果。第二個是空的 – Azukah
在第二個循環之前使用'mysql_field_seek($ qry_offers,0)',但我更喜歡Ansrew的答案! – undone