Re: 10 rows

From: Date: Thu, 04 Jan 2007 02:20:56 +0000
Subject: Re: 10 rows
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-42878@lists.php.net to get a copy of this message
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? <a href="http://www.host.com/script.php?next=21">Next Link</a> <a href="http://www.host.com/script.php?previous=1">Previous Link</a>
You can either do it like that or just pass the page number across: <a href="http://www.domain.com/script.php?page=1">Prev</a> Viewing page 2 <a href="http://www.domain.com/script.php?page=3">Next</a> It's up to you.. Either way make sure you validate your data: <?php $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/

« previous php.db (#42878) next »