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.

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.