The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 2 of 2

Thread: [PHP & MySQL] Pagination Help!

  1. #1
    jw06's Avatar
    657
    posts
    Registered User

    [PHP & MySQL] Pagination Help!

    I'm having some problems with a tutorial that I found from phpfreaks. It doesnt seem to be showing links at the bottom of the page and what not. It shows page one, but with no hyperlink.

    Here is the code:

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php 

        
    @mysql_connect('localhost''portfolio''**') or die("ERROR--CAN'T CONNECT TO SERVER"); 
        @
    mysql_select_db(portfolio) or die("ERROR--CAN'T CONNECT TO DB"); 

        
    $limit          7;                
        
    $query_count    "SELECT count(*) FROM news";     
        
    $result_count   mysql_query($query_count);     
        
    $totalrows      mysql_num_rows($result_count); 

        if(empty(
    $page)){ 
            
    $page 1
        } 
             

        
    $limitvalue $page $limit - ($limit); 
        
    $query  "SELECT * FROM news LIMIT $limitvalue$limit";         
        
    $result mysql_query($query) or die("Error: " mysql_error()); 

        if(
    mysql_num_rows($result) == 0){ 
            echo(
    "Nothing to Display!"); 
        } 

        
    #$bgcolor = "#E0E0E0"; // light gray 

        
    echo("<table>"); 
         
           while (
    $row mysql_fetch_array ($result)) {
            
    //echo '<center>';
            
    echo "<div id=\"entrytitle\">{$row['title']} - {$row['date_entered']}</div>";
            echo 
    "<div id=\"entrycontent\">{$row['entry']}</div><br />";
            
    //echo '</center>';
        
    }

        if(
    $page != 1){ 
            
    $pageprev $page--; 
             
            echo(
    "<a rel="nofollow" target=\"frame\" href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a>&nbsp;"); 
        }else{ 
            echo(
    "PREV".$limit."&nbsp;"); 
        } 

        
    $numofpages $totalrows $limit
         
        for(
    $i 1$i <= $numofpages$i++){ 
            if(
    $i == $page){ 
                echo(
    $i."&nbsp;"); 
            }else{ 
                echo(
    "<a rel="nofollow" target=\"frame\" href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;"); 
            } 
        } 


        if((
    $totalrows $limit) != 0){ 
            if(
    $i == $page){ 
                echo(
    $i."&nbsp;"); 
            }else{ 
                echo(
    "<a rel="nofollow" target=\"frame\" href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;"); 
            } 
        } 

        if((
    $totalrows - ($limit $page)) > 0){ 
            
    $pagenext $page++; 
              
            echo(
    "<a rel="nofollow" target=\"frame\" href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); 
        }else{ 
            echo(
    "NEXT".$limit); 
        } 
         
        
    mysql_free_result($result); 

    ?> 
    </body>
    </html>

  2. #2
    Quote Originally Posted by jw06
    I'm having some problems with a tutorial that I found from phpfreaks. It doesnt seem to be showing links at the bottom of the page and what not. It shows page one, but with no hyperlink.

    PHP Code:
    if(empty($page)){ 
    $page 1

    how many rows are in the DB? if u are only getting one without a link then there isnt 7 in there, as 7 is your display limit

    PHP Code:
    if(empty($_POST['page'])){ 
    $page 1

    else {
    $page $_POST['page'];


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012