Jump to content

Pagination tip


dhimok

Recommended Posts

Hello everyone. Can u help me with some pagination issue

 

I want to put a pagination on bottom of the page and I have like 100 page numbers or more, so I want to show only 5 page numbers on both sides of the current page, if u know what i mean like

 


Prev .. 8 9 10 11 12 13 14 15 16 17 .. Next

 

when i move to the right or left then i add or subtract one. Here 's what i have so far

 

 


for ($i = 1; $i <= $numPages; $i++) { 
        echo " "; 
        if ($i == $pageNum) 
            echo "$i";
        else 
            echo "<a href=\"?page=$i\">$i</a>"; 
}

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/61850-pagination-tip/
Share on other sites

if ($currentpage > 1){
$x = $currentpage - 1;
echo "<a href=\"$x\">Prev</a> ";
}
if ($currentpage > 5){
echo "... "
$b = $currentpage - 5;
}else{
$b = 1;
}
for ($i = $b; $i <= $numPages; $i++) { 
        echo " "; 
        if ($i == $pageNum){
            echo $i;
}elseif(($currentpage+5)>$i){ 
            echo "<a href=\"?page=$i\">$i</a>"; 
}else{
break;
}
}
if (($currentpage + 5) < $numPages){
echo " ...";
}
if ($currentpage!=$numPages){
$x = $currentpage + 1;
echo " <a href=\"$x\">Next</a>";
}

 

Maybe something along the lines of this... not the cleanest code but i believe it should work.

Made a small edit. Try it out and see if it works.

Link to comment
https://forums.phpfreaks.com/topic/61850-pagination-tip/#findComment-308068
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.