#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    51
    Rep Power
    3

    Help refining my pagination function


    hello everyone.

    I have a pagination function below. the function works perfectly.

    The problem, however , is that some of my search results have over 200 pages. i therefore need to find a way to refine my function so that it only shows the page numbers for the first 10 pages and then skips to the last 10 pages.

    i am however unclear how to go about doing this.

    the page pagination is below
    PHP Code:



    // Number of records to show per page:
        
    $display 9;
        
        
    // Determine how many pages there are...
        
    if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined.
        
            
    $pages $_GET['p'];
        
            
        } else { 
    // Need to determine.
        




    // Count the number of records:
            
        
    $q "SELECT COUNT(membership_type) FROM users
                   WHERE
                   membership_type= 'travellers' "
    ;
        
        
    $detailedview = @mysqli_query ($dbc$q);
        
    $row = @mysqli_fetch_array ($detailedviewMYSQLI_NUM);
        
    $records $row[0];
             
    //echo $records;


        // Calculate the number of pages...
        
    if ($records $display) { // More than 1 page.
            
    $pages ceil ($records/$display);
        } else {
            
    $pages 1;
        }
        
    // End of p IF.

    // Determine where in the database to start returning results...
    if (isset($_GET['s']) && is_numeric($_GET['s'])) {
        
    $start $_GET['s'];
    } else {
        
    $start 0;
    }



        
    // Make the links to other pages, if necessary.
    if ($pages 1) {
        
        
    // Add some spacing and start a paragraph:
        
    echo '<br /><p>';
        
        
    // Determine what page the script is on:    
        
    $current_page = ($start/$display) + 1;
        
        
    // If it's not the first page, make a Previous button:
        
    if ($current_page != 1) {
            echo 
    '<a href="index.php?view=view&s=' . ($start $display) . '&p=' $pages '">Previous</a> ';
        }
        
        
    // Make all the numbered pages:
        
    for ($i 1$i <= $pages$i++) {
            if (
    $i != $current_page) {
                echo 
    '<a href="index.php?view=view&s=' . (($display * ($i 1))) . '&p=' $pages '">' $i '</a> ';
            } else {
                echo 
    $i ' ';
            }
        } 
    // End of FOR loop.
        
        // If it's not the last page, make a Next button:
        
    if ($current_page != $pages) {
            echo 
    '<a href="index.php?view=view&s=' . ($start $display) . '&p=' $pages '">Next</a>';
        }
        
        echo 
    '</p>'// Close the paragraph.
        
    // End of links section. 
    thank you for your help

    warm regards

    Andreea
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2007
    Posts
    1,513
    Rep Power
    1423
    Well, this part is displaying the page number links:

    php Code:
    // Make all the numbered pages:
        for ($i = 1; $i <= $pages; $i++) {
            if ($i != $current_page) {
                echo '<a href="index.php?view=view&s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
            } else {
                echo $i . ' ';
            }
        } // End of FOR loop.


    You will have to change the start and the running condition of this loop.

    Regards, Jens

IMN logo majestic logo threadwatch logo seochat tools logo