View Single Post
Old 03-17-2010, 10:15 PM   #28 (permalink)
REFFER
The Visitor
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
REFFER is on a distinguished road
Default

Here one simple solution for people looking for pagination...
Just a few changes in the code and it works fine.


PHP Code:
    $max 3;
    if (
is_numeric($_GET['p'])){
        
$p $_GET['p'];
        if (
$p<1$p 1;
    } else {
        
$p 1;
    }
    
    
$limit = ($p $max) - $max;
    
    
$conn mysql_connect("localhost","user","pass");
    
mysql_select_db("db_name",$conn);
    
    
$query_count "SELECT * FROM `table`";
    
$result mysql_query($query_count);
    
$rows = @mysql_num_rows($result);
    
$numOfPages ceil($rows/$max);
    
    if (
$p>$numOfPages$p $numOfPages;
    
    
$query $query_count " LIMIT $limit$max";
    
$result mysql_query($query);
    

    while (
$data mysql_fetch_object($result)){
        echo 
$data->field."<br />";
    }
    
    echo 
"<br /><br />";

    if (
$p>1){
        
$prev $p 1;
        echo 
'<a href="?p='.$prev.'">Previous</a> ';
    }
    for (
$i=1;$i<=$numOfPages;$i++){
        if (
$i == $p){
            echo 
"<b>$i</b> ";
        } else {
            echo 
'<a href="?p='.$i.'">'.$i.'</a> ';
        }
    }
    if (
$p<$numOfPages){
        
$next $p 1;
        echo 
'<a href="?p='.$next.'">Next</a>';
    } 

Last edited by REFFER : 03-18-2010 at 02:13 AM.
REFFER is offline  
Reply With Quote