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
https://forums.phpfreaks.com/topic/79507-breaking-up-pages-to-a-few-at-a-time/
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> ';
            }
            
        } 

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.