Chris Carter wrote:
I am trying to paginate this to display just 4 results and use <Previous and
Next> options for pagination.
// database information
$query="SELECT * FROM students LIMIT";
You need to use LIMIT offset, number.
limit 50, 10 <- start at position 50, get 10 records.
To make this work reliably, you also need to order your results.
Unless you specify an 'ORDER BY' clause the database will return them in
any order it sees fit and probably won't order things correctly. It
might get it right a lot of the time but the only way to guarantee it is
to tell it how to order the results.
So you should end up with something like this:
$number_to_fetch = 10;
$start_page = (isset($_GET['Start'])) ? (int)$_GET['Start'] : 0;
$offset = $start * $number_to_fetch;
$query = "select * from students ORDER BY student_id LIMIT " . $offset .
", " . $number_to_fetch;
Then when you go to the next page, 'Start' will be 1.
Postgresql & php tutorials
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php