Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Pagination Error

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

    Default

    Quote Originally Posted by djr33 View Post
    $nextTxt = '<a href="">Next>></a>'; // Echo next page link
    ...an actual HREF might be helpful
    $nav .= ' <a href="">'.$i.'</a> '; // Echo link to the page
    ...same
    Also noted the

    Code:
    if ($page_num > 1) {
    $prev = $pag_nume ...
    }
    Shouldn't that be page_num?

    Now as far as the page not showing up anything (just blank), or is it showing up the page links at least? Nowhere in your code (the code you posted at least) does it show anything about displaying (spelling?) stuff.

    It could be something else in your code (the part[s] you are not posting.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    Well, I am trying to have pagination to limit the amount of links showed on a page in a link manager. There are also some member view scripts that I would like to use this on. I am attempting to use things that I have seen, so I could be totally wrong in what I am doing. If anyone would be so kind, could you show me what a pagination script should look like? Thanks again
    Thanks DD, you saved me countless times

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

    Default

    Well, that's all the pagination script does with the exception of a few things. I don't have time to post a code example, because I am getting ready for work right now. As soon as I get in I will post an example for you, unless someone else does before.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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

    Default

    Quote Originally Posted by thetestingsite View Post
    Well, that's all the pagination script does with the exception of a few things. I don't have time to post a code example, because I am getting ready for work right now. As soon as I get in I will post an example for you, unless someone else does before.
    Ok, thanks. I myself am getting ready for work at the moment, so I understand the lack of time
    Thanks DD, you saved me countless times

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

    Default

    Code:
    <?php
    
    ##### Pagination Example (Not Tested, but should work) #####
    $page = $_GET['page']; //request and assign the page variable
    
    $max = 20; //how many results per page
    
    
    $start = ($page * $max);
    
    
    $count_results = mysql_query("SELECT * FROM `links` ORDER BY id DESC"); // Get data from database
    
    $count_total = mysql_num_rows($count_results); // Count lines in database
    
    $total_pages = ceil($count_total / $max); // Total results divided by max to display
    
    if($page > 1) { // Is the page # more than one?
    
        $prev = ($page - 1); // If yes, take one away from current page
        $prevTxt = '<a href="?page='.$prev.'">&lt;&lt;Previous</a>'; 
    } 
    
    $nav = ' ';
    
    for($i == 1; $i <= $total_pages; $i++) // For each page number
    
        if($page == $i) { // If page = current page
        
            $nav .= '<b>'.$i.'</b>'; // Echo page in bold
        } else {
        
            $nav .= ' <a href="?page='.$i.'">'.$i.'</a> '; // Echo link to the page
        }
        
    if($page < $total_pages) { // Is there another page?
    
        $next = ($page + 1); // If so, add 1 to current page
        $nextTxt = '<a href="?page='.$next.'">Next>></a>'; // Echo next page link
    }
    
    ##### End Pagination and Start Displaying the page #####
    
    $info = mysql_query("SELECT * FROM `links` ORDER BY id DESC LIMIT $start, $max"); // Get data from database and limit to the max results
    
       while ($qry = mysql_fetch_array($info)) {
            $link = $qry['link'];
    
           echo '<div>'.$link.'</div> <br>';
       }
    
    echo 'Pages: '.$prevTxt . $nav . $nextTxt; //display the page links
    ?>
    That will produce anything that is extracted from the sql for that page. You may want to play around with it a little bit, but the script should work with very little modification.

    Hope this helps.
    Last edited by thetestingsite; 02-13-2007 at 02:58 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #16
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, I wrote out a new script and it works pretty good. There are a few errors though. The first is that it seems to display results in reverse order. The second is that the last page is not displayed. Here is the code:
    PHP Code:
    <?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 2;
    // 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);

    // Run query
        
    $sql "SELECT * FROM `test` ORDER BY id DESC LIMIT $cur$max";
        
    $result mysql_query($sql) or die ('Error Getting Data! <br />' .mysql_error());
        
    // 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;$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 />'
    ;
        }

    echo 
    'Pages: '.$prevLink $nav $nextLink;
    ?>
    Thanks for the help
    Thanks DD, you saved me countless times

  7. #17
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This will work

    PHP Code:
    <?php

    $max 
    2// max number of results

    // Calculate paging
    if ((isset($_GET['page'])) && (is_numeric($_GET['page']))) {
        
    $page $_GET['page'];
        if (
    $page == 0) {$page 1;} // just in case someone put in 0 for the page
    } else { $page 1; }
        
    $offset = ($page-1)*$max// offset of the query
    $qlimit =  " LIMIT {$offset},{$max}"// limit part of the query

    // Build the query
    $order " ORDER BY id DESC"// method of order
    $basequery "SELECT * FROM test" $order;
    $query $basequery $qlimit;

    // Show pages links
    $pttl mysql_num_rows(mysql_query($basequery)) or die ('Error Getting Data! <br />' .mysql_error());
    $numpages ceil($pttl/$max); // count the number of pages
    $pagelinks NULL// define a variable for the page links

    // If theres more than 1 page
    if ($numpages 1) {    
        
    $prev $page-1$next $page+1// set previous and next
        
        // if its not page 1 show previous link
        
    if ($page 1) {$pagelinks .= " <a href=\"?page={$prev}\">&lt;&lt;Previous</a>&nbsp;";}
        
        
    // print the links
        
    for ($p 1$p <= $numpages$p++) {
            
    // if its the current page make it bold
            
    if ($p == $page) {$pagelinks .= " <b>{$p}</b>";}
            
    // else make it a link
            
    else {$pagelinks .= " <a href=\"?page={$p}\">{$p}</a>";}
        }
        
        
    // if its not the last page print the next link
        
    if ($page $numpages) {$pagelinks .= "&nbsp;&nbsp;<a href=\"?page={$next}\">Next&gt;&gt;</a> ";}
        
        
    // finally build the final page links
        
    $pagelinks "Pages ({$numpages}):{$pagelinks}";
    }

    // Run the query
    $results mysql_query($query) or die ('Error Getting Data! <br />' .mysql_error());
    while (
    $row mysql_fetch_assoc($results)) {
        echo 
    $row['title'] . "<br />";
    }

    echo 
    $pagelinks// print the pagelinks

    ?>

  8. #18
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried using your code, mechatama25 and when I try to go to the page, the page will load extremely slow, but the rest of the pages on the server don't. Then sometimes it will not load, but when it does, nothing is there. I could be wrong, but it seems to me like the code is intentionally made to do something to the server to slow it down.
    Thanks DD, you saved me countless times

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

    Default

    Titan, the code you posted just after my example does in fact work with very little modification. For a test of it, simply check out this page. If you would like the source code, click here. The sql data is here.

    Let me know if you need any further help.
    Last edited by thetestingsite; 02-15-2007 at 04:59 AM.

  10. #20
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Titan, the code you posted just after my example does in fact work with very little modification. For a test of it, simply check out . If you would like the source code, click here. The sql data is here.

    Let me know if you need any further help.
    Yeah, it works mostly, but there is an error (or perhaps lack of code) in displaying the page number link (1,2,3,etc). On the first page, it shows 1 in bold, but not 2, and on page 2, it displays the link to page 1, but not the current page in bold. Is this just a part of code missing? thanks again
    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
  •