MySQLで奇数と偶数を組み合わせるにはどうすればよいですか?
これは、ページごとに 10 個のレコードがあり、新しい順に配置されたページング コードです。
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> $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 '<ul class="left">'; } if($num ==5){ echo '<ul class="right">'; } //这里的代码如何写,才能按单双数并类? if($num%5==0){ echo '</ul>'; } $num++; }
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <ul class="left"> <li> 1st result </li> <li> 3rd result </li> <li> 5th result </li> <li> 7th result </li> <li> 9th result </li> </ul> <ul class="right"> <li> 2nd result </li> <li> 4rd result </li> <li> 6th result </li> <li> 8th result </li> <li> 10th result </li> </ul>
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> ul ul ------------ ------------ | 1st result | 2nd result | ------------ ------------ | 3rd result | 4th result | ------------ ------------ | 5th result | 6th result | ------------ ------------ | 7th result | 8th result | ------------ ------------ | 9th result | 10th result| ------------ ------------
$num = 1; while($row = mysql_fetch_array($sql)){ if($num% 2) { $left[] = '<li>'.$row['title'].'</li>'; } else $right[] = '<li>'.$row['title'].'</li>'; } echo "<ul class='left'>".implode("",$left).'</ul'>; echo "<ul class='right'>".implode("",$right).'</ul'>; <br><font color="#e78608">------解決策------------------</font><br>ポインタを移動してもできます<div class="clear"></div>