Re: 10 rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux