Thread: Pagination
View Single Post
Old 06-14-2009, 07:28 AM   #5 (permalink)
Randy
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

Alright read that got a question:

I am trying to make it display all page numbers without doing the "..." things and I cant seem to figure out how I would go about doing that lol.

My code is pretty much exactly the same as his, but his code seems quite messy in my opinion.

Any thoughts?

PHP Code:
            <?php
            
            
// define variables
            
$pageNumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1;
            
            
// establish number per page
            
$perPage 5;
            
            
// establish padding value
            
$padding 2;
            
            
// get start index of results
            
$startIndex = ($pageNumber $perPage) - $perPage;
            
            
// get total number of database entries
            
$totalCount "SELECT COUNT(*) as 'Total' FROM adminforum_question";
            
$rsCount mysql_query($totalCount) or die(mysql_error());
            
$rowCount mysql_fetch_object($rsCount);
            
            
// show page listings
            
echo "<div class=\"pagination\">";
            
                
// get total number of pages
                
$numOfPages ceil($rowCount->Total $perPage);
                
                
// print link to first page
                
if (($pageNumber != 0) && ($PageNumber != 1) && ($pageNumber != $numOfPages)) {
                }
                
?>
                
                <span class="pages">Page <?php echo $pageNumber ?> of <?php echo $numOfPages ?> </span>
                
                <?php
                
// if our current page, minus padding, greater tthen 1
                
if (($pageNumber $padding) > 1) {
                    echo 
"... ";
                        
// set lower limit
                        
$lowerLimit $pageNumber $padding;
                        
// print all padded numbers between lowerlimit and current page
                        
for($i $lowerLimit$i $pageNumber$i++) {
                            echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                        }
                } else {
                    
// print all numbers between current page and first page
                    
for($i 2$i $pageNumber$i++) {
                        echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                    }
                }
                
                
// if were not on first page, or last page, print current page
                
if (($pageNumber != 0) && ($PageNumber != 1) && ($pageNumber != $numOfPages)) {
                    echo 
"<b> - " $pageNumber ." - </b>";    
                }
                
                
// if current page, plus padding, less then total number of pages
                
if(($pageNumber $padding) < $numOfPages) {
                    
//  set upper limit
                    
$upperLimit $pageNumber $padding;
                    
// print all numbers from padding pages above current page
                    
for($i = ($upperLimit +1); $i $pageNumber$i++) {
                        echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                    }
                    echo 
"... ";
                } else {
                    
// print all page numbers between number of pages and current page
                    
for($i = ($pageNumber 1); $i $numOfPages$i++) {
                        echo 
"<a href=\"index.php?page=".$i."\">".$i."</a> ";
                    }
                }

            echo 
"</div>";
?>
Basically I want it to look like this:
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford

Last edited by Randy : 06-14-2009 at 07:30 AM. Reason: added image
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote