i’m a newbie in php especially on making pagination.
my question is, how to make paging like stackoverflow’s pagination?
i mean paging like this :
1 … 5 6 7 8 9 … 25
(the first number and the last number is always appear, but in the middle only 5 numbers with the selected page absolutely in the middle)
in php i have tried making paging,
<?php
//Show page links
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
but it will be shown all of pages like
1 2 3 4 5 6 7 8 9 10 etc
any body have simple logic example to solve this problem?
many thanks 🙂
Below is a snippet from a general pagination class1 I wrote a few years ago. I have edited it to show the relevant parts only.
Example 1
cntAround = 1,current = 5,cntPages = 9:Example 2
cntAround = 3,current = 5,cntPages = 11:1) Article is in Danish. Google Translate’d version is here.