日期:2014-05-17 浏览次数:20521 次
$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++;
}
<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>
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'>;
------解决方案--------------------
也可通过移动指针完成