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!

Keeping search criteria thru pages

Status
Not open for further replies.

vidyaR

Programmer
Jul 14, 2001
5
US
Hi,
I'm new to CF and here is my problem.
When my query returns more than 20 recs, I split them up into pages and use href to create a link to pages. But when i try to change page, the search criteria is not carried over and I get a listing of the entire records. How do I pass the search criteria to the links?

thanks,
v
 
If the search criteria is fairly small you can add it on as a URL variable like this:

<A Href=&quot;Results.cfm?Criteria=dogs&Page=2&quot;>Click For More</A>

you can access these variables on the page as

#URL.Criteria# which is &quot;dogs&quot;
and #URL.Page# which is 2

This way you could call the same page and just increase the Page variable to see the next results. Of course that all depends on how you have it set up. But that is a way to pass variables through an Href.

Hope it helps. If that wont work for you there are other ways we can try. Let me know if it doesn't work and exactly what the information that you need to pass is. We'll figure it out.

 
Hi tlhawkins,
I had a whole lot of criteria; name, address, institution, email, etc. Since posting the question, I tried creating a variable urlParameters, added all the criteria to it and used it wherever I was using href to link. It worked. Please let me know if there is any better way to do it.
Thanks for your response.
-v
 
That sounds very good vidyaR,

The only time you want to do it another way is when you have a whole Query to pass (I usually just re-Query), or if it is imperitive that you do not have URL variables. You have to watch for errors if someone book marks a page while you have URL variables set, it can make things wierd.

Another way that you may want to look into is Cookies (most people don't like them, I personally avoid them but they are an option)

I'm glad you got it working!
 
tlhawkins, When you want to pass a query or a re-query elsewhere but in the url, do you do it using session.varname or something different? Thanks
 
Yes sergei, I use Session variables. (Be sure to read up on them, they have some idiosyncracies)

Usually what I do is pass the ID to the next page and make another query on the new page with the ID. Sometimes that isn't practical or even possible and then you can pass an entire Query as a Session variable although I've heard some people have problems getting that to work.

Hope it all works for you.
 
How to put limited number of number of records on a page. for example, 10 and have ohter records in ohter page. how to specify that.


also how to have next and previous links?
 
I think the easiest way would be to pass the STARTROW on the URL.

Then your QUERY output would look like this:

<CFLOOP Query=&quot;MYQUERY&quot; StartRow=&quot;#URL.Start#&quot; EndRow=&quot;#URL.StartRow#+25&quot;>

#MYSTUFF#

</CFLOOP>

Then you can make the Next and Previous links by simply passing a lower or higher #URL.Start#
<CFSET Prev=#URL.Start#-25>
<CFSET Next=#URL.Start#+25>
Like : <A Href=&quot;Thispage.cfm?Start=#Prev#>Previous</A>
ANd <A Href=&quot;ThisPage.CFM?Start=#Next#>Next</A>

Have fun....

Let me know if you have any problems with that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top