Re: 10 rows
am 29.12.2006 06:32:36 von Darryl Ware
Ron Piggott (PHP) wrote:
> "I would normally just pass the offset through the get var."
>
>
> I understand what you are saying in concept ... but what would a
> sample command be like?
>
> Next Link
> Previous Link
>
> Ron
How you pass it is incidental really, the variable name is only for your
benefit, so these are as valid as the next way of doing it.
To learn more you may want to google for "pagination php" and that will
put you onto plenty of great tutorials.
Darryl.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: 10 rows
am 04.01.2007 03:20:56 von Chris
Ron Piggott (PHP) wrote:
> "I would normally just pass the offset through the get var."
>
>
> I understand what you are saying in concept ... but what would a sample
> command be like?
>
>
>
You can either do it like that or just pass the page number across:
Viewing page 2
It's up to you..
Either way make sure you validate your data:
$number_of_records_per_page = 20;
$page = 1;
if (isset($_GET['page'])) {
$page = (int)$_GET['page'];
}
if ($page < 1) {
$page = 1;
}
.....
so people can't put in strings (xss or sql injection attacks) as the
'page' number - and so if it goes below 1 it gets reset to the first page.
$start_record = ($page-1) * $number_of_records_per_page;
I take 1 off so the first page is '1' not '0'.
The query then comes out as:
$query = "select .... limit " . $start_record . ", " .
$number_of_records_per_page;
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php