Here is some php mysql query code. I want make some query with pagination. each page have 10 results.
$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">';
}
//what about these code here?
if($num%5==0){
echo '</ul>';
}
}
And I want out put the html like:
<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>
So, how to add html tags in this situation? Thanks.
you are not incrementing $num
try this
$num = 1;
while($row = mysql_fetch_array($sql)){
if($num ==1){
echo '<ul class="left">';
}
if($num ==5){
echo '<ul class="right">';
}
//what about these code here?
if($num%5==0){
echo '</ul>';
}
$num++ ;
}
Try this code:-
$num = 1;
$ul_first= '<ul class="left">';
$ul_second= '<ul class="right">';
while($row = mysql_fetch_array($sql)){
if(($num%2)==1){
$ul_first.= '<li>'.$row['result'].'</li>';
}
if(($num%2)==0){
$ul_second.='<li>'.$row['result'].'</li>';
}
if(($num%10)==0){
$ul_first.= '</ul>';
$ul_second.= '</ul>';
}
$num++ ;
}
echo $ul_first;
echo $ul_second;