Solved

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

Posted on 2009-04-22
179 Views
hello,

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
\$amountofpages
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);

}
0
Question by:jblayney
1 Comment

LVL 39

Accepted Solution

Use the ceil() function, it rounds up:

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

0

## Featured Post

### Suggested Solutions

As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.