I have a list of user comments stored in a database and I'm displaying 10 per page. On page load I need to dynamically render the appropriate amount of page numbers. At first I thought I would just get the total amount of comments and divide that by 10 to get the # of pages. That however doesn't work correctly. For example:
1. 1-10开发者_StackOverflow中文版
2. 11-21
3. 22-32
4. 33-43
5. 44-54
6. 55-65
7. 66-76
So basically with my original math if I have 70 results I will have 7 pages, but if I have 71 results I get 8 pages, which obviously isn't correct. How can I fix this?
Here's my original code:
<cfset commentsNumber = getComments.recordcount / 10>
<cfloop from="1" to="#commentsNumber#" index="i" >
<cfoutput>
#i#
</cfoutput>
</cfloop>
Edit: I can't do math today :(
...if I have 71 results I get 8 pages, which obviously isn't correct.
10 results per page w/ 71 results is 8 pages. What's wrong?
If you want to be sure of your record paging in ColdFusion, you could use an open source library like Pagination.cfc. It handles all the math for you and gives you a customizable display.
hey correct you math first.. :) your example is wrong. If you are showing 10 comments per page then it should be 1. 1-10 2. 11-20 3. 21-30 etc
By the way you can use CFGRID for paging... it's very simple..
精彩评论