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

Multiple reults problem. <CFLOOP>

Status
Not open for further replies.

DrDan2

Technical User
Nov 22, 2002
24
GB
Was wondering if anyone can see anything wrong with my code here. It supposed to bring up a reulst page which is limited to 10 results at a time, with a newxt and previous link to navigate to other records. The end result, when the form returns the Country variable, is a line of the link "Next" instead of displaying the results. There are as many Next links as there are Countries. E.g If the search was for South Africa, and there were 13 in the database, 13 Nexts would be displayed. Here is my code. Sorry about the length but I don't want to miss anything out.----------------------------------------------------

<CFQUERY Name=&quot;DiveSearch&quot; DATASOURCE=&quot;DiveSchools&quot;>
Select *
From DiveData
Where Country='#Country#'
</CFQUERY>

<CFPARAM NAME=&quot;CountR&quot; DEFAULT=&quot;1&quot;>


<HEAD><TITLE>Search Results</TITLE></HEAD>

<BODY>

<CFOUTPUT QUERY=&quot;DiveSearch&quot;>
<CFIF CountR GT 1>
<CFSET Prev=CountR - 10>
<CFIF Prev LT 1><CFSET Prev=1></CFIF>
<A HREF=&quot;SearchResults.cfm?CountR=#Prev#>Previous Page</A>
</CFIF>

<CFIF CountR LT (DiveSearch.RecordCount - 9)>
<CFSET Next=CountR+10>
<CFIF Next GT DiveSearch.Recordcount><CFSET Next=DiveSearch.recordcount-1></CFIF>
<A HREF=&quot;SearchResults.cfm?CountR=#Next#>Next Page</a>
</CFIF>


<CFSET Start=CountR>
<CFIF Start LT 1><CFSET Start=1></CFIF>
<CFIF Start GT DiveSearch.RecordCount><CFSET Start=DiveSearch.RecordCount></CFIF>

<CFSET End=CountR+9>
<CFIF End GT DiveSearch.recordCount><CFSET End=DiveSearch.RecordCount></CFIF>

<CFLOOP From=#Start# to=#End# INDEX=SearchResultLoop>
#OrgName#, #Country#, #Email# #City#<p>
</CFLOOP>



<CFIF CountR GT 1>
<CFSET Prev=CountR - 10>
<CFIF Prev LT 1><CFSET Prev=1></CFIF>
<A HREF=&quot;SearchResults.cfm?CountR=#Prev#>Previous Page</A>
</CFIF>

<CFIF CountR LT (DiveSearch.RecordCount - 9)>
<CFSET Next=CountR+10>
<CFIF Next GT DiveSearch.Recordcount><CFSET Next=DiveSearch.recordcount-1></cfif>
<A HREF=&quot;SearchResults.cfm?CountR=#Next#>Next Page</a>
</CFIF>
</CFOUTPUT>
</BODY>
 
You've got the &quot;next&quot; in the cfoutput with the results... so CF is processing it as it should...

Change:

Code:
  <CFIF CountR GT 1>
    <CFSET Prev=CountR - 10>
    <CFIF Prev LT 1><CFSET Prev=1></CFIF>
    <A HREF=&quot;SearchResults.cfm?CountR=#Prev#>Previous Page</A>
  </CFIF>

  <CFIF CountR LT (DiveSearch.RecordCount - 9)>
    <CFSET Next=CountR+10>
    <CFIF Next GT DiveSearch.Recordcount><CFSET Next=DiveSearch.recordcount-1></cfif>
    <A HREF=&quot;SearchResults.cfm?CountR=#Next#>Next Page</a>
  </CFIF>
</CFOUTPUT>

to

Code:
</CFOUTPUT>
<CFOUTPUT><CFIF CountR GT 1>
    <CFSET Prev=CountR - 10>
    <CFIF Prev LT 1><CFSET Prev=1></CFIF>
    <A HREF=&quot;SearchResults.cfm?CountR=#Prev#>Previous Page</A>
  </CFIF>

  <CFIF CountR LT (DiveSearch.RecordCount - 9)>
    <CFSET Next=CountR+10>
    <CFIF Next GT DiveSearch.Recordcount><CFSET Next=DiveSearch.recordcount-1></cfif>
    <A HREF=&quot;SearchResults.cfm?CountR=#Next#>Next Page</a>
  </CFIF></CFOUTPUT>

A cfoutput with no attributes just reads through once, no looping..

Tony ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
DOH! Silly me. Thanks. That problem solved. Another ones popped up. Now when it returns the search results, it displays each records the same number of times that there are returned records. If there are 10 records returned, then each one is displayed 10 times, so I end up with 100.
this is my Code so far. Thanks again. Oh yeah. What's the INDEX for in <CFLOOP>?

<CFQUERY Name=&quot;DiveSearch&quot; DATASOURCE=&quot;DiveSchools&quot;>
Select *
From DiveData
Where Country='#Country#'
</CFQUERY>

<CFPARAM NAME=&quot;CountR&quot; DEFAULT=&quot;1&quot;>


<HEAD><TITLE>Search Results</TITLE></HEAD>

<BODY>

<CFOUTPUT>
<CFIF CountR GT 1>
<CFSET Prev=CountR - 10>
<CFIF Prev LT 1><CFSET Prev=1></CFIF>
<A HREF=&quot;SearchResults.cfm?CountR=#Prev#&quot;>Previous Page</A>
</CFIF>

<CFIF CountR LT (DiveSearch.RecordCount - 9)>
<CFSET Next=CountR+10>
<CFIF Next GT DiveSearch.Recordcount><CFSET Next=DiveSearch.recordcount-1></CFIF>
<A HREF=&quot;SearchResults.cfm?CountR=#Next#&quot;>Next Page</a><br>
</CFIF>
</CFOUTPUT>


<CFSET Start=CountR>
<CFIF Start LT 1><CFSET Start=1></CFIF>
<CFIF Start GT DiveSearch.RecordCount><CFSET Start=DiveSearch.RecordCount></CFIF>

<CFSET End=CountR+9>
<CFIF End GT DiveSearch.recordCount><CFSET End=DiveSearch.RecordCount></CFIF>

<CFOUTPUT QUERY=&quot;DiveSearch&quot;>
<CFLOOP From=#Start# to=#End# INDEX=DiveSearch>
#OrgName#, #Country#, #Email# #City#<p>
</CFLOOP>
</CFOUTPUT>
 
Never mind, but thanks. I got that sorted out now. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top