Pagination Tutorial
am 16.10.2007 13:40:32 von AlecNewbie question.
I have recently tried a php tutorial on pagination, but I just cannot
get the links to work. See www.freeweekends.co.uk/pagtest2.php. The
search finds over 60 results, but only the first page of ten are
displayed, with the Prev and Next links not working.
Can anyone help, or has anyone another pagination tutorial?
Thanks
Alec
$connection = @mysql_connect('localhost', '*****', '*****');
if (!$connection) {
echo '
Unable to make database connection.
';exit();
}
if (!@mysql_select_db('uks49179')) {
exit('
Unable to locate database.
');}
$limit = 10;
$query_count = "SELECT count(*) FROM companyid_uks49179 WHERE
town='Bury St. Edmunds' AND category='sleep' AND priority='0'";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT company FROM companyid_uks49179 WHERE town='Bury
St. Edmunds' AND category='sleep' AND priority='0' 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("
if($page != 1){
$pageprev = $page--;
echo("
");
}else{
echo("PREV".$limit." ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo(" ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo(" ");
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("NEXT".$limit."
a>");
}else{
echo("NEXT".$limit);
}
mysql_free_result($result);
?>