这是一个分页的代码,每页十条记录,按时间倒序排列。
$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>
HTML 视图 ul ul
------------ ------------
| 1st result | 2nd result |
------------ ------------
| 3rd result | 4th result |
------------ ------------
| 5th result | 6th result |
------------ ------------
| 7th result | 8th result |
------------ ------------
| 9th result | 10th result|
------------ ------------
$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>
HTML 视图 ul ul
------------ ------------
| 1st result | 2nd result |
------------ ------------
| 3rd result | 4th result |
------------ ------------
| 5th result | 6th result |
------------ ------------
| 7th result | 8th result |
------------ ------------
| 9th result | 10th result|
------------ ------------
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'>;
服务端的话,肯定要遍历,毕竟从表里出来的时候就是数组
服务端的话,肯定要遍历,毕竟从表里出来的时候就是数组