[web] PHP Questions about diving items into pages

This topic is 3549 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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 on other sites
Have a look at the floor(), ceil() and intval() functions.

As for MySQL:

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

Share on other sites
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.

1. 1
Rutin
19
2. 2
JoeJ
15
3. 3
4. 4
5. 5

• 24
• 20
• 13
• 13
• 17
• Forum Statistics

• Total Topics
631700
• Total Posts
3001778
×