Thread: Pagination
View Single Post
Old 04-04-2006, 07:50 AM   · #2
Noobie
DNOA Member
 
Noobie's Avatar
 
Name: Shoei
Location: Montreal, Quebec, Canada
Trader Rating: (0)
Join Date: Feb 2006
Posts: 324
NP$: 65.00 (Donate)
Noobie is on a distinguished road
I use PEAR :: Pager now because i'm just totally in love with PEAR ... but this is how I used to do it (i got this off a tutorial a long time ago and modified it)

PHP Code:
$max_results = 30;    //maximum entries to show per page
if(!isset($_GET['page'])){
    
$page = 1;
}else {
    
$page  = $_GET['page'];
}
$sql = "SELECT * FROM `tutorials` WHERE category = 'photoshop'";
$select = mysql_query($sql, $connect);
$totalrows = mysql_num_rows($select );
$minval = (($page * $max_results) - $max_results);
$sql .= " LIMIT $minval, $max_results";
$select = mysql_query($sql, $connect);
while(
$row = mysql_fetch_array($select, MYSQL_ASSOC)) {
    
$id = $row['id'];
    
$name = $row['name'];
    
$email = $row['email'];
    
$category = $row['category'];
    
$url = $row['url'];
    
$url2 = $row['url2'];
    
$websitename = $row['websitename'];
    
$tutorialname = $row['tutorialname'];
    
$description = $row['description'];

echo
"
    <p>
     <strong>Tutorial Name:</strong> <a href=\"$url2\">$tutorialname</a><br />\n
    <strong>Submitted By:</strong> <a href=\"$url\">$websitename</a><br />\n
    <strong>Description:</strong> $description</p>"
;
}
# pagination
$total_pages = ceil($totalrows / $max_results);
if(
$page > 1){
    
$prev = ($page - 1);
    echo
"<a href=\"?id=$id&page=$prev\">&lt;</a>&nbsp;";
}
for(
$i = 1; $i <= $total_pages; $i++){
      if(
$i % 30 == 0) {echo "<br>\n";} // How many page numbers you want per line
    
if(($page) == $i){
       echo
"$i&nbsp;";
        } else {
     echo
"<a href=\"?id=$id&page=$i\">$i</a>&nbsp;";
        }
    }
    if(
$page < $total_pages){
    
$next = ($page + 1);
    echo
"<a href=\?id=$id&page=$next\">&gt;</a>";
}

?>


Please register or log-in into NamePros to hide ads
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline   Reply With Quote
Site Sponsors
EscrowDNS http://www.mobisitetrader.com/ EscrowDNS
Advertise your business at NamePros
All times are GMT -7. The time now is 11:53 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.