0

I have this php page that displays all the record from the database.
now, I want them to look something like this..

1. result A

2. result B

3. result C

There's a lot of records in my database, so it has several pages.(each page displays 20 records)

now if i go from page 1 to 2 to 3 to 4 ....if its increasing. the numbers shown are correct.
but if i go from page 2 to 1, or from page 5 to 1 the numbering is wrong.


Google use to have numbered search results but its gone now, so I got no reference.
That's what I want to achieve.

Please help. thank you.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by EvolutionFallen
0

You can make the links for your separate pages of results look like this:

<a href="mysite.php?page=1">Page 1</a>
<a href="mysite.php?page=2">Page 2</a>

Then when the page loads, before the DB query executes:

$RESULT_LIMIT = 20;
// make sure $_GET['page'] is an integer
if(!strcmp(gettype($_GET['page']), 'integer') {
   $page = $_GET['page'];
   $result_start = ($page - 1) * 20; // If page 1, start at item 0, if page 2, start at item 20, etc...
}
$query = 'SELECT fieldname FROM tablename WHERE something=somethingelse LIMIT '.$result_start.', '.$RESULT_LIMIT;

Edited by EvolutionFallen: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.