Jump to content

Pagination Link Problem


phpbeginner

Recommended Posts

I have the simple pagination script from the tutorials and I can't seem to get the page links to work .....

 

<?php 


    $limit          = 5;                
    $query_count    = "SELECT count(*) FROM homes where area='$area'";     
    $result_count   = mysql_query($query_count);     
    $totalrows      = mysql_num_rows($result_count);  

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

    $limitvalue = $page * $limit - ($limit);  
    $query  = "SELECT * FROM homes where area='$area' ORDER BY `price` ASC LIMIT $limitvalue, $limit";         
    $result = mysql_query($query) or die("Error: " . mysql_error());  

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

    while ($a_row =mysql_fetch_array ($result) )
{

 

My page information is displaying here correctly and the limit function works but below my page numbers will not link. If I manually type in the address bar mylink&page=3, the 1 at the bottom is linked and I can then go back to mylink&page1

 

} 	
    if($page != 1){  
        $pageprev = $page--; 
         
        echo("<a href=\"$PHP_SELF?area=$area&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=\"$PHP_SELF?area=$area?page=$i\">$i</a> "); 
        } 
    } 


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

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

?>

 

Thanks for your help and patience with me !

Link to comment
https://forums.phpfreaks.com/topic/46656-pagination-link-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.