| DNOA Member Name: Shoei Location: Montreal, Quebec, Canada Join Date: Feb 2006
Posts: 324
NP$: 65.00 ( Donate)
| 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\"><</a> ";
}
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 ";
} else {
echo "<a href=\"?id=$id&page=$i\">$i</a> ";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\?id=$id&page=$next\">></a>";
}
?> |