profwannabe
Programmer
I am trying to provide a navigation through pages that display 15 records each: Jump to page: 1 2 3 4, etc. Here is the code thus far:
<cfparam name="STARTROW" default="1">
<tr><td>
<cfoutput query="getModelList" group="Model" startrow=#StartRow# maxrows=15>
#UCase(Trim(Model))#<br>
</cfoutput>
</td></tr>
<!-- the navigation -->
<tr><td>
<cfoutput>Displaying Results #StartRow# - #ENDROW# of #getModelList.RecordCount#.</cfoutput>
</td></tr>
<tr><td>Jump to page:
<cfset PageIndex = getModelList.RecordCount / 15 + 1>
<cfloop index="PageNumber" from="1" to="#PageIndex#">
<cfoutput> <cfset NextStartRow = (#PageNumber#-1)*15 + 1> <a href="locator.cfm?fuseaction=dspSelectModel&#application.addtoken#&StartRow=#NextStartRow#&OEMSelect=#attributes.OEMSelect#&SearchText=#attributes.searchtext#">#PageNumber#</a>
</cfoutput>
</cfloop>
</td></tr>
It seems to work fine, with two small exceptions:
First: I set the PageIndex to getModelList.RecordCount/15 + 1, because I was losing the last page of the results unless the record count was evenly divisable by 15 (i.e. if RecordCount/15 = 7.3333, I was getting 7 pages). Of course, I now have the problem that IF the record count is evenly divisable, I end up with a page displaying no records! How can I account for a remainder > 0?
Second: The output line "Displaying results #STARTROW# - #ENDROW#..." is inaccurate for the last page, since ENDROW is not a count of the number of rows on the page but merely STARTROW + 14. How can I count the rows displayed to generate this value (using MAXROWS to limit my display)?
<cfparam name="STARTROW" default="1">
<tr><td>
<cfoutput query="getModelList" group="Model" startrow=#StartRow# maxrows=15>
#UCase(Trim(Model))#<br>
</cfoutput>
</td></tr>
<!-- the navigation -->
<tr><td>
<cfoutput>Displaying Results #StartRow# - #ENDROW# of #getModelList.RecordCount#.</cfoutput>
</td></tr>
<tr><td>Jump to page:
<cfset PageIndex = getModelList.RecordCount / 15 + 1>
<cfloop index="PageNumber" from="1" to="#PageIndex#">
<cfoutput> <cfset NextStartRow = (#PageNumber#-1)*15 + 1> <a href="locator.cfm?fuseaction=dspSelectModel&#application.addtoken#&StartRow=#NextStartRow#&OEMSelect=#attributes.OEMSelect#&SearchText=#attributes.searchtext#">#PageNumber#</a>
</cfoutput>
</cfloop>
</td></tr>
It seems to work fine, with two small exceptions:
First: I set the PageIndex to getModelList.RecordCount/15 + 1, because I was losing the last page of the results unless the record count was evenly divisable by 15 (i.e. if RecordCount/15 = 7.3333, I was getting 7 pages). Of course, I now have the problem that IF the record count is evenly divisable, I end up with a page displaying no records! How can I account for a remainder > 0?
Second: The output line "Displaying results #STARTROW# - #ENDROW#..." is inaccurate for the last page, since ENDROW is not a count of the number of rows on the page but merely STARTROW + 14. How can I count the rows displayed to generate this value (using MAXROWS to limit my display)?