I am working on bloging software, in which right now shows every post. I know there is some mathematical equasion to make it show like 20 per-page. I don't know it.
Summary:
Could someone make a code to only allow 20 posts to show per page. Also, an overflow generator that would create the second page, third page, fourth and so on. If possible also explain this for future reference.
Thanks in advance,
Scott W.
Row Divider
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Row Divider
Equation? There is no equation, it's called pagination. 
That SQL code will SELECT all records from 1 to 25, if you wanted to SELECT all records on second page, you would say, 26, 51. Perhaps you meant that equation, for calculating pagination details?
1. Determine the total number of records in your resultset, lets say 1000.
2. Determine how many records you want displayed per page, lets say 10.
3. Calculate the total number of pages needed to partition your resultset, 1000 / 10 = 10
You have 10 pages, each with 10 records each totaling 1000 records.
Cheers,
Alex
Code: Select all
$sql = "SELECT * FROM table LIMIT, 25";1. Determine the total number of records in your resultset, lets say 1000.
2. Determine how many records you want displayed per page, lets say 10.
3. Calculate the total number of pages needed to partition your resultset, 1000 / 10 = 10
You have 10 pages, each with 10 records each totaling 1000 records.
Cheers,
Alex
Re: Row Divider
you'll be hard up for someone here to write it FOR you. but we can definitly help.
what you are trying to do is called paginating. there are lots of threads on this forum and google that will help.
basically what you want to do is:
1) use an SQL count statement with your query to get how many results you are working with.
2) calculate how many pages there will be based on how many you want to display per page.
3) in your SQL SELECT statement you will want to use LIMIT command to limit your results to 20.
for example (with LIMIT): LIMIT 0, 20 would be your first SQL statement. the first variable is where to start (0 = the beginning) and the second is how many per page.
so in reality you would want have something like this: (SELECT * FROM table LIMIT {$offset}, {$per_page})
we use variable $offset because your offset is going to change... we also use $per_page because you may want to make that user selectable.
so your next button would send a value to change the offset. so for page 2: LIMIT 20, 20. for page 3: LIMIT 40, 20.
Make sense? I know I didnt go into mush detail... but like I said, there are lots of other threads on here and google that can help you figure it out the rest of the way.
what you are trying to do is called paginating. there are lots of threads on this forum and google that will help.
basically what you want to do is:
1) use an SQL count statement with your query to get how many results you are working with.
2) calculate how many pages there will be based on how many you want to display per page.
3) in your SQL SELECT statement you will want to use LIMIT command to limit your results to 20.
for example (with LIMIT): LIMIT 0, 20 would be your first SQL statement. the first variable is where to start (0 = the beginning) and the second is how many per page.
so in reality you would want have something like this: (SELECT * FROM table LIMIT {$offset}, {$per_page})
we use variable $offset because your offset is going to change... we also use $per_page because you may want to make that user selectable.
so your next button would send a value to change the offset. so for page 2: LIMIT 20, 20. for page 3: LIMIT 40, 20.
Make sense? I know I didnt go into mush detail... but like I said, there are lots of other threads on here and google that can help you figure it out the rest of the way.
Re: Row Divider
@PCSpectra: You're a PHP genius, but you flunk Arithmetic!PCSpectra wrote:1. Determine the total number of records in your resultset, lets say 1000.
2. Determine how many records you want displayed per page, lets say 10.
3. Calculate the total number of pages needed to partition your resultset, 1000 / 10 = 10
You have 10 pages, each with 10 records each totaling 1000 records.