Jump to content

Recommended Posts

the best place to start is the mysql LIMIT clause, which you tag onto the end of your SELECT. it takes either 1 or 2 parameters - 1 if you just want to pick a certain number of rows, 2 if you want to pick a certain number of rows starting from a particular record - which is what you need for pagination. there's a tutorial right here on phpfreaks that describes the basics well: http://www.phpfreaks.com/tutorials/43/0.php

this, for example, will pick 5 records starting from the very first record (0 signifies the first record, not 1):
SELECT * FROM mytable LIMIT 0, 10

this would pick 5 rows on "page" 3:
SELECT * FROM mytable LIMIT 20, 10

pagination generally involves passing the page number in the URL and passing the resulting $_GET['page'] into your LIMIT clause.

http://php.about.com/od/mysqlcommands/g/Limit_sql.htm

here's a little example pseudocode to set you on your way:
[code]
<?php
// how many results per page?
$num_per_page = 10;

// what record shall we start at?
$offset = ($_GET['page'] - 1) * $num_per_page;

$query = "SELECT * FROM mytable LIMIT $offset, $num_per_page";

... etc ...


?>
<a href="/mypage.php?page=1">Page 1</a>
<a href="/mypage.php?page=2">Page 2</a>
<a href="/mypage.php?page=3">Page 3</a>
etc
etc
[/code]

cheers
Mark
Link to comment
https://forums.phpfreaks.com/topic/24770-pages-of-data/#findComment-112790
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.