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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resultset not working 1

Status
Not open for further replies.

oaklandar

Technical User
Feb 12, 2004
246
US
I am trying to get the Resultset page listing to work for my page. It works great for all pages 10 and under but when I get over 10 pages it doesnt work correctly:

For example if I have 11 page results and I go to page 2 it will show page 11 as the current page:
1 2 3 4 5 6 7 8 9 10 11

If I have resultset under 10 pages it works great. For example on page 2 it will look like this:
1 2 3 4 5
or if I am on page 4 it will look like this:
1 2 3 4 5


Please advise because I have tried many ways to get a resultset similiar to what is set up on this tek-tips and other sites such as google.

Here is my attempt that is very close but not working correctly with anything over 10 pages:

Code:
<cfparam name="myStart" default="1">
<cfparam name="myDisplay" default="10">

<cfquery name="myQuery" datasource="myQuery" dbtype="ODBC">
select * from myQuery 
</cfquery> 
					
<cfoutput query="myQuery" startrow="#myStart#" maxrows="#myDisplay#">
							
<table width="60%" align="center">
<TR>
<td>
<a href="[URL unfurl="true"]http://mydiretory/myQuery/myPage.cfm?id=#myQuery.id#">#subject#</a></td>[/URL]
</tr>
</table>
				
</cfoutput>	

<cfset NumPages=Ceiling(myQuery.RecordCount / myDisplay)>

    <cfloop from="1" to="#NumPages#" index="ThisPage">
      <cfoutput>
        <cfif ThisPage IS myStart>
          <td>#ThisPage#</td>
        <cfelse>
          <cfset PageNumStart=(((ThisPage - 1) * myDisplay) + 1)>
          <td><a href="thePage.cfm?id=#myQuery.id#&StartRow=#PageNumStart#&myStart=#PageNumStart#">#ThisPage#</a></td>
        </cfif>
      </cfoutput>
    </cfloop>
 
Code:
<cfset NumPages=Ceiling(myQuery.RecordCount / myDisplay)>
<cfloop from="1" to="#NumPages#" index="ThisPage">
      <cfoutput>
        <cfif ThisPage IS myStart>
          <td>#ThisPage#</td>
        <cfelse>
          <cfset PageNumStart=(((ThisPage - 1) * myDisplay) + 1)>
          <td><a href="thePage.cfm?id=#myQuery.id#&StartRow=#PageNumStart#&myStart=#PageNumStart#">#ThisPage#</a></td>
        </cfif>
      </cfoutput>
    </cfloop>

I'm not sure how this works at all.
lets say your query has 110 rows.

that makes
numpages = 11
default value for mystart = 1
second pass in loop
pageNumStart = (2-1)*10+1 = 11

then you set both url.startRow and url.mystart to pagenumStart (11) third pass you set mystart to (21)

StartRow=#PageNumStart#&myStart=#PageNumStart#


If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
It does compute correctly on my page for under 10 pages.
Do you or anyone have something better I can use?

Thanks.
 
i still don't see how it works with less than 10 either.

say you have 5 pages.
the third and forth loops set "myStart" to 41 and 51 respectivly. if you click 4 mystart = 41
You then compair "thispage" which will be 1-5, in this case 4, it never matches up. is there code you didn't include?

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
oops i ment 4th and 5th loops.

but anyway.

it seems like
StartRow=#PageNumStart#&myStart=#PageNumStart#
should be
StartRow=#PageNumStart#&myStart=#thispage#

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top