mysql如何按單雙數結果並類?
這是一個分頁的代碼,每頁十條記錄,按時間倒序排列。
PHP code
$sql = mysql_query("SELECT * FROM article WHERE uid='132828' ORDER BY date LIMIT ".$number.",10 ");$num = 1;while($row = mysql_fetch_array($sql)){ if($num ==1){ echo ''; } if($num ==5){ echo ''; } //這裡的代碼如何寫,才能按單雙數並類? if($num%5==0){ echo '
'; } $num++;}
最後我想輸出的結果是
HTML code
- 1st result
- 3rd result
- 5th result
- 7th result
- 9th result
- 2nd result
- 4rd result
- 6th result
- 8th result
- 10th result
HTML 視圖
HTML code
ul ul ------------ ------------| 1st result | 2nd result | ------------ ------------| 3rd result | 4th result | ------------ ------------| 5th result | 6th result | ------------ ------------| 7th result | 8th result | ------------ ------------| 9th result | 10th result| ------------ ------------
------解決方案--------------------
PHP code
$num = 1;while($row = mysql_fetch_array($sql)){ if($num % 2) { $left[] = '
'.$row['title'].''; } else $right[] = '
'.$row['title'].'';}echo "
".implode("",$left).';echo "".implode("",$right).';
------解決方案--------------------
也可通過移動指標完成 -