For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > January 2007 > Re: [PHP-DB] 10 rows









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] 10 rows
Chris

2007-01-03, 9:59 pm

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/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com