i have pagination system on my echo results however, the page numbers are being echo’ed underneath eachother
e.g.
1
2 3 4 5
this is my code:
for($i=0;$i < $count1;$i=$i+$limit)
{
if($i <> $start)
{
echo "<a href='view.php?search=$search&start=$i&limit=$limit&price=$price&category=$category'><font face='Verdana' size='2'><b> $l </b></font></a> ";
}
else
{
echo "<center><font face='Verdana' size='4' color=#2E9AFE ><b> $l </b></font></center>";
}
MODIFIED CODE:
$i=0;
$l=1;
echo "<p align='left'>";
for($i=0;$i < $count1;$i=$i+$limit)
{
if($i <> $start)
{
echo '<a href="view.php? search=$search&start=$i&limit=$limit&price=$price&category=$category">$i</a>';
}
else
{
echo '<span class="current">$i</span>';
}
$l=$l+1;
}
echo "</p>";
}
Here is another way of doing the above, with a few added extras:
(the above requires php5+)
With regards to neeko’s comment, to seperate the
$startvariable from the text displayed in the link – all you have to do is either introduce another variable that counts up with each loop – or, as we already have the key of the range array, we can use that:I’ve used
$key + 1, because$keywill be zero-based (i.e. counting up from Zero) but the +1 just shifts things so we count up from 1 instead.