Jump to content

pagination ... only showing so many links


runnerjp

Recommended Posts

i have a few things in trying to do

 

1.

 <?php echo "...<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$totalpages\"echo $totalpages</a>  "; ?>

im trying to make it so it shows the lastpage number... 

<?php $numofpages = $rows / $page_rows;
    $totalpages = ceil($numofpages);?>

but it wont echo it out :S

 

also atm my links look like this

 

<? 
    echo "<br>"; 
} 
echo "<p>"; 


//// Find out the total number of pages depending on the limit set
    $numofpages = $rows / $page_rows;
    $totalpages = ceil($numofpages);
// Start links for pages
$maxpage = $totalpages == 0 ? 1 : $totalpages; // add this line
echo "<p align=center>Page $pagenum of $maxpage <br /> "; // change this

// Sets link for previous 25 and return to page 1
    if($pagenum != 1){
        $pageprev = ($pagenum - 1);
         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=1\"><<</a>  ";
}


// Loop thru all the pages and echo out the links
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $pagenum){
            echo "[".$i."] ";
        }else{
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$i\">$i</a> ";
        }
    }

// Check for straglers after the limit blocks
    if(($rows % $page_rows) != 0){
        if($i == $pagenum){
            echo "[".$i."] ";
        }else{
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$i\">$i</a> ";
        }
    }
// Print out the Next 25 and Goto Last page links
    if(($rows - ($page_rows * $pagenum)) > 0){
        $pagenext = $pagenum++;
     
          echo "...<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$totalpages\"echo $totalpages</a>  ";
    }else
echo "</p>";
?>

 

im trying to show my links liek this

 

[1] 2 3 4 5 ...56 <= last page

 

but im not sure how to only echo upto 5 pages out?

 


 

Link to comment
https://forums.phpfreaks.com/topic/130717-pagination-only-showing-so-many-links/
Share on other sites

i didn't read through everything, but i did notice that this:

echo "...<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$totalpages\"echo $totalpages</a>  ";

 

should be this (i think this is what you were going for...):

echo "...<a href=\"".$_SERVER['PHP_SELF']."?page=message&id=$id&pagenum=$totalpages\">".$totalpages."</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.