SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination issue

    Hi,

    Iím trying to put together a pagination script in php. The records get called out, but the next / previous buttons donít <a href> despite there being over 25 entries?

    Iím hoping itís something blatently obvious someone can tell me!

    Many Thanks

    Chris

    PHP Code:
    <?php 

        
    include('************');
        
    $can_i_connect db_connect(); // by db_connect function is in my include file
        
        
    if(!$can_i_connect)
            {
            echo 
    "Could not connect to database";
            }

        
    $limit          10;                
        
    $query_count    "SELECT count(*) FROM directory_listings";     
        
    $result_count   mysql_query($query_count);     
        
    $totalrows      mysql_num_rows($result_count);  

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

        
    $limitvalue $page $limit - ($limit);  
        
    $query  "SELECT * FROM directory_listings 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)){ 
            if (
    $bgcolor == "#E0E0E0"){ 
                
    $bgcolor "#FFFFFF"
            }else{ 
                
    $bgcolor "#E0E0E0"
            } 

        echo(
    "<tr bgcolor=".$bgcolor."><td>"); 
        echo(
    $row["company_name"]); 
        echo(
    "</td><td>"); 
        echo(
    $row["town"]); 
        echo(
    "</td></tr>"); 
        } 

        echo(
    "</table>"); 

        if(
    $page != 1){  
            
    $pageprev $page--; 
             
            echo(
    "<a href=\"test.php&page=$pageprev\">PREV".$limit."</a> ");  
        }else{ 
            echo(
    "PREV".$limit." "); 
        } 

        
    $numofpages $totalrows $limit;  
         
        for(
    $i 1$i <= $numofpages$i++){ 
            if(
    $i == $page){ 
                echo(
    $i." "); 
            }else{ 
                echo(
    "<a href=\"test.php?page=$i\">$i</a> "); 
            } 
        } 


        if((
    $totalrows $limit) != 0){ 
            if(
    $i == $page){ 
                echo(
    $i." "); 
            }else{ 
                echo(
    "<a href=\"text.php?page=$i\">$i</a> "); 
            } 
        } 

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

    ?>

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At a glance the problem seems to be the number of pages, try:
    if( $totalrows % $limit==0)$numofpages = $totalrows / $limit;
    else $numofpages = ($totalrows / $limit)+1;

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2006
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another thing, change ur query to:

    $query_count = "SELECT * FROM `directory_listings`";
    and use prefix++ instead of postfix.

  4. #4
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - sorted it now


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
  •