Posted by Kim Andrι Akerψ on 04/19/07 15:49
Man-wai Chang wrote:
> > Hi. You can use the query to do it for you, without PHP or stored
> > procedures.
> > SELECT * FROM table LIMIT 0, 10
>
> page 1 is easy. What about pageno > 1?
Using PHP (with explanations):
// Number of items per page.
$pagesize = 10;
// Get the page number from the user input.
$pageno = intval($_GET["page"]);
// In case "page=" in the URL query string was set to 0,
// a negative number, or not set at all.
if ($pageno < 1) { $pageno = 1; }
// Calculate the offset based on the page size and given page number.
$offset = ($pageno - 1) * $pagesize;
// Perform the
$query = "SELECT * FROM myTable LIMIT ".$offset.", ".$pagesize;
$result = mysql_query($query);
--
Kim AndrΓ© AkerΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
[Back to original message]
|