# [web] PHP Questions about diving items into pages

## Recommended Posts

Portishead    122
I've been looking for a way to divide items into pages, and I've finnally figured it out. I have some questions about the way that I wasn't sure of This is the process: Y = the number of comments in each page X = the number of the page 1.Count the total number of comments into Z 2.Divide Z by Y 3.Make sure that X != 0 and X is not bigger than the result of Z:Y My question is about step 2: Assuming Z is 75 and Y is 10. The result is 7 and a rest of 5. Will the result in the PHP code be exactly 7 or 7 and some number after the point(7.XXX)? If it does count the numbers after the point, I can see if number is exactly 7 or bigger than 7, and if it is bigger, I can count it as 8? Would that work? This is the formula I did to get the comments that belong to the page: y(x-1)+1 =< comments =< yx My question is how do I put this formula into a SELECT mySQL query? Do you find any probelms with the formula? Thanks in advance, Portishead.

#### Share this post

##### Share on other sites
Sander    1332
Have a look at the floor(), ceil() and intval() functions.

As for MySQL:

SELECT * FROM Z_table LIMIT (X - 1) * Y, Y;

#### Share this post

##### Share on other sites
Sonnenblume    222
I've not got time to go into it in great detail just now, but the correct term for this process is 'pagination'. A quick google should help you figure out the process, combined with the functions Sander listed.

The trick is to use PHP to figure out what range of pages your wishing to display. Once you know that, use the mysql limit command to control which pages are returned.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now