What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP Pagination help

PHP Pagination help
Author: Message:
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: PHP Pagination help
I'm not going to do it for you, but I'll explain a bit what you should be doing.

Set a variable $perpage somewhere that'll define how many results are displayed per page. Also let's say you're getting the page number via $_GET['page'].

You'll want to use MySQL's "LIMIT" operator. The syntax is start,count where start is the row's offset and count is how many rows after the offset to return.

Use this algorithm to calculate the start position:

$start = ($page - 1) * $perpage;

and use $perpage as the count.

When page is 1, start = 0 which is the beginning
When page is 2, start = perpage * 1 which is perpage (the next set)
When page is 3, start = perpage * 2 which is the last start position + perpage
etc

For example:

code:
$page = intval($_GET['page']);
$start = ($page - 1) * $perpage;
$query = mysql_query("SELECT * FROM search WHERE description LIKE '%" . $search . "%' LIMIT $start,$perpage");
$numrows=mysql_num_rows($query);


$numrows will tell you how many results you got back. If you get none, then obviously there are too few results to show that page. As for displaying links to other pages, that's up to you.
The previous sentence is false. The following sentence is true.
04-20-2006 05:37 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
PHP Pagination help - by DJeX on 04-20-2006 at 01:08 AM
RE: PHP Pagination help - by Lou on 04-20-2006 at 01:15 AM
RE: PHP Pagination help - by DJeX on 04-20-2006 at 01:58 AM
RE: PHP Pagination help - by segosa on 04-20-2006 at 05:37 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On