# Doubles in PHP

• Apr 11, 2009, 14:08
JordashTalon
Doubles in PHP
I'm trying to write a page generation script but some of my calculations will come out to decimal places.

For example

\$var=10/3;

would give about 3.333 I would need to round that to 4

or basically

\$var=\$a/\$b and always round up, how would I do that?

Thanks
• Apr 11, 2009, 14:17
Mark Baker
PHP Code:

``` \$var=ceil(\$a/\$b)  ```
• Apr 11, 2009, 14:27
JordashTalon
Thanks, got a logic question related to this,

Let's say i'm displaying 3 items per page and I generate a query string to tell me which page i'm on:

example: http://domain.com/thepage?pageOn=page

\$pageOn=\$_GET['pageOn'];

so if i'm on page 1 I start listing things starting from position 1 in the database table, then if I'm on Page 2 I start listing from point 4 and if i'm on page 3 I start listing from Page 7. How would I calculate where to start from.

page 1=start 1;
page 2=start 4;
page 3=start 7;

I think it's some type of Algebraic Equation.
• Apr 11, 2009, 14:33
Mark Baker
C'mon, this is absolutely basic mathematics:
Code:

`\$start = ((\$page -1) * \$items_per_page) + 1`
• Apr 11, 2009, 14:41
JordashTalon
You're running into the same problem I am, because after page 3 (it works fine up till page 3) on page 4 it resolves to starting at point 10 when it should start at 11, like below:

page 1=start 1;
page 2=start 4;
page 3=start 7;
page 4=start 11;
page 5=start 15;
page 6=start 18;
• Apr 11, 2009, 14:47
JordashTalon
Wait hold on, my problem was in the way I was displaying the pages, you did it right (I was doing it right except for the page calculations) it's working.

Thanks!
• Apr 11, 2009, 14:55
crmalibu
btw, they call this pagination if you want to search for more info.
• Apr 11, 2009, 15:24
JordashTalon
good to know, thanks