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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.