Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: Pagination Error

  1. #21
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Sorry Titan, forgot to post the actually link to the page for the example (fixed now). Can you post a link (or pm me a link) to the problem page as so I can take a look at it?

  2. #22
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Sorry Titan, forgot to post the actually link to the page for the example (fixed now). Can you post a link (or pm me a link) to the problem page as so I can take a look at it?
    I sent a pm
    Thanks DD, you saved me countless times

  3. #23
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, so I had a further look at the code and came up with the following.

    Code:
    <?php
         include('dbconnect.php');
               
    // If page is set
    if($_GET['page'] && is_numeric($_GET['page'])) {
        $page = $_GET['page'];
    }
    
    // Set default page
    else {
        $page = 1;
    }
    
    // Max results per page
    $max = 7;
    
    // Current page
    $cur = (($page * $max) - $max);
    
    // Get data
    $qry = mysql_query("SELECT * FROM `test`");
    $total = mysql_num_rows($qry); // count results
    
    // Get amount of pages
    $total_pages = ($total / $max);
        
    // Is page # more than one
    if($page > 1) {
        $prev = ($page - 1);
        $prevLink = '<a href="?page='.$prev.'">&lt;&lt;Previous</a>';
    }
    
    // For each page less than total pages
    for($i=1;$i<$total_pages+1;$i++) {
        // If page = current page
        if($page == $i) {
            $nav .= ' <b>'.$i.'</b> ';
        } else {
            // Echo link to previous page
            $nav .= ' <a href="?page='.$i.'">'.$i.'</a> ';
        }
    }
    
    // If page is less than total pages, show next link
    if($page < $total_pages) {
        $next = ($page + 1);
        $nextLink = '<a href="?page='.$next.'">Next&gt;&gt;</a>';
    }
    
    ########## End Pagination Script ##########
    
    $info = mysql_query("SELECT * FROM `test` ORDER BY `id` DESC LIMIT $cur, $max");
    
        while($row = mysql_fetch_array($info)) {
            echo $row['title'].'
            <br />';
        }
    
    if ($total_pages > 1) {
    echo 'Pages: '.$prevLink . $nav . $nextLink;
    }
    
    ?>
    Notice the part in red that I edited. I have tested it, and it works as it should.

    Hope this helps.

    PS: I also pm'd you the code.

  4. #24
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks, its working great now
    Thanks DD, you saved me countless times

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •