You are here: Pagination Tutorial « PHP Programming Language « IT news, forums, messages
Pagination Tutorial

Posted by Alec on 10/16/07 11:40

Newbie 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

<?php
$connection = @mysql_connect('localhost', '*****', '*****');
if (!$connection) {
echo '<p>Unable to make database connection.</p>';
exit();
}
if (!@mysql_select_db('uks49179')) {
exit('<p>Unable to locate database.</p>');
}

$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("<table>");

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

echo $row['company']."<br />";

}

echo("</table>");

if($page != 1){
$pageprev = $page--;

echo("<a href=\"$PHP_SELF?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?page=$i\">$i</a> ");
}
}

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

if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;

echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</
a>");
}else{
echo("NEXT".$limit);
}

mysql_free_result($result);

?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация