Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Navigating through grouped output results

Status
Not open for further replies.

profwannabe

Programmer
Jan 6, 2001
53
US
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=&quot;STARTROW&quot; default=&quot;1&quot;>
<tr><td>
<cfoutput query=&quot;getModelList&quot; group=&quot;Model&quot; 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=&quot;PageNumber&quot; from=&quot;1&quot; to=&quot;#PageIndex#&quot;>
<cfoutput> <cfset NextStartRow = (#PageNumber#-1)*15 + 1> <a href=&quot;locator.cfm?fuseaction=dspSelectModel&#application.addtoken#&StartRow=#NextStartRow#&OEMSelect=#attributes.OEMSelect#&SearchText=#attributes.searchtext#&quot;>#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 &quot;Displaying results #STARTROW# - #ENDROW#...&quot; 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)?
 
Hey Prof,

for problem 1, this should work better.

<cfset PageIndex = ceiling(getModelList.RecordCount / 15)>

for problem 2, try this.

<cfset endRow = startRow + 15>
<cfif endRow gt getModelList.RecordCount>
<cfset endRow = getModelList.RecordCount>
</cfif>

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top