Jump to content

Breaking up pages to a few at a time


brent123456

Recommended Posts

if($num_pages > 1) {
            // determine what page the script is on.
            $current_page =($start/$display) + 1;

            // if not on the first page make a previous page
            if ($current_page != 1) {
                echo '<a href="index.php?do=requestpage&s=' . ($start - $display) . '&np=' . $num_pages .
                        '"> Prev </a> ';
            }

            // make all the numbered pages
            for ($i = 1; $i <= $num_pages; $i++) {
                if($i != $current_page) {
                    echo '<a href="index.php?do=requestpage&s=' . (($display * ($i - 1))) . '&np=' .
                    $num_pages . '">' . $i . '</a>';
                } else {
                    echo $i . '';
                }
            }
            // if it's not the last page , make a next button.
            if ($current_page != $num_pages) {
                echo '<a href="index.php?do=requestpage&s=' . ($start + $display) . '&np=' . $num_pages .
                        '"> Next </a> ';
            }
            
        }

 

I am having trouble trying to figure out how to break this up into only a few pages at a time like <prev 3 4 5 next> instead of 1234567891011121314 next>.

 

Could anyone offer me a hand with this it would be a big help. Thanks.

Link to comment
Share on other sites

Thank you, I Have looked this over but I am still having trouble figuring out he logic to get the pages. $x only prints out 789 everytime but the pages only go till 7 so far. I am not really sure were to implement the number of pages in my paging code.

 

$totalpage = 100;
$pagelimit=3;//3row
$p=(int)($num_pages/$pagelimit)+1;
echo $p;
$pagedisplay =$p*$pagelimit; 
$num_pages = $pagedisplay - 3+1 ;
for ($x = $num_pages;$x<=$pagedisplay;$x++){
    echo $x;
}
         if($num_pages > 1) {
            // determine what page the script is on.
            $current_page =($start/$display) + 1;

            // if not on the first page make a previous page
            if ($current_page != 1) {
                echo '<a href="index.php?do=requestpage&s=' . ($start - $display) . '&np=' . $num_pages .
                        '"> Prev </a> ';
            }

            // make all the numbered pages 
            ffor ($x = $num_pages;$x<=$pagedisplay;$x++){    
                if($i != $current_page) {
                    echo '<a href="index.php?do=requestpage&s=' . (($display * ($i - 1))) . '&np=' .
                    ($display*$x) . '"> ' . $x . ' </a>';
                } else {
                    echo $x . '';
                }
            }
            // if it's not the last page , make a next button.
            if ($current_page != $num_pages) {
                echo '<a href="index.php?do=requestpage&s=' . ($start + $display) . '&np=' . $num_pages .
                        '"> Next </a> ';
            }
            
        } 

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.