• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

if a number is a multiple of another number for recordset paging


I built a recordset paging function.  

i use a few variables such as
$number_per_page = 6;
that is how many records i want to show on every page

another which is important is
this number is a calculation of how many page links to display (eg Page1,2,3,...), i get that number like this...

$query_Recordset_paging = "SELECT * FROM shoes WHERE shoes_brand = $id ORDER BY shoes_name ASC";
$Recordset_paging = mysql_query($query_Recordset_paging, $mine) or die(mysql_error());
$totalRows_Recordset_paging = mysql_num_rows($Recordset_paging);

$amountofpages = round($totalRows_Recordset_paging / $number_per_page  + .5);

Basically i get the total rows and divide it by the $number_per_page and add .5 to round up all the pages

The problem is when i have an amount of pages which is a multiple of $number_per_page for example if $amountofpages = 12, or 18   I will get an extra page which has no results...

i tried the code below but it doesnt help....
if ($amountofpages % $number_per_page   == 0) {
    $amountofpages = ($amountofpages - 1);

Open in new window

1 Solution
Roger BaklundCommented:
Use the ceil() function, it rounds up:

$amountofpages = ceil($totalRows_Recordset_paging / $number_per_page);

Open in new window


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now