[SOLVED] Results 1 - 10 of 50

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

Results 1 - 10 of 50

Post by zenabi »

When a search is carried out in Google it shows something similar to this near the top of the page:

Results 1 - 10 of 50

I am having trouble working out how to do this (I have already implemented pagination).

From the example above (the search is limited to 10 results per page), 1 is simple to achieve, as is 50 (the total number of results), but I can't seem to figure out how to get the 10.

It's late and it's probably very simple to solve, so I am grateful to anyone who can help. Just the logic will be fine, but if it helps to explain your answer in php then it will be appreciated.

Cheers
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$start = ($pagenum-1) * $numperpage + 1;
$stop = $start + $numperpage - 1;
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

If you implemented pagination perhaps there are variables in your code like

Code: Select all

$results_per_page; // constant or adjustable by user
  $start_result; // from request
  $total_results; // from query
so 10 is $start_result + $results_per_page - 1
zenabi
Forum Commoner
Posts: 84
Joined: Mon Sep 08, 2003 5:26 am
Location: UK

Post by zenabi »

Thanks guys, much appreciated.
Post Reply