Re: Display Records in Multiple Pages
| From: | Richard Lynch | Date: | Sun, 30 Jun 2002 22:38:29 +0000 |
| Subject: | Re: Display Records in Multiple Pages | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-104765@lists.php.net to get a copy of this message | ||
In article <009a01c21da7$7c215b60$1300a8c0@redplanet> , aqua@sas.co.id
(Aqua) wrote:
>I have 100 records in mySQL database and I need to display them in my web
>page using php and html. How to display them in multiple pages? Each page
>must contain 25 records. Does anyone know how to do it other than create 4
>pages and manually list the records there? or maybe point me some reference
>please. Your help will be much appreciated. Thanks!
Search MySQL's site or PHPBuilder/WeberDev/etc for an example of the LIMIT
clause.
Or, very briefly:
<?php
if (!isset($start)){
$start = 0;
$limit = 25;
}
$query = "select blah from mytable limit $start, $limit";
$records = mysql_query($query) or error_log(mysql_error()); #check http
error_log for errors!
while (list($blah) = mysql_fetch_row($records)){
echo "$blah<BR>\n";
}
echo "<A HREF=samepage.php?start=", $start - 25, ">Prev</A>";
echo "<A HREF=samepage.php?start=", $start + 25, ">Next</A>";
?>
You'll want to check that you don't go over 100 or under 0, and that there
actually *IS* a Next/Prev page, but this is the core of it.
--
Like Music? http://l-i-e.com/artists.htm