views:

20

answers:

1

I need a formula for showing results on my classifieds website.

I am now done with the paging of records, but this formula for showing results remains.

I want it like this:

  Showing 1-50 of 123 found.

Now what is the formula for this?

I have these variables which should be enough I think:

  $results_per_page = 50; //results per page
  $page = 1; //current page
  Also a variable called $num_total contains the total nr of hits, in this case 123.

Thanks

+2  A: 

Is this what you want?

<?php

$page = 1;
$results_per_page = 50;
$num_total = 123;

echo 'Showing ' . ((($page - 1) * $results_per_page) + 1)
                . '-' . min($num_total, ($page * $results_per_page))
                . ' of ' . $num_total . ' found.';

?>
Alix Axel
@Camran: Do you want me to write the `if ($num_total > 0)`?
Alix Axel