Skip to main content
August 6, 2010
Answered

Having a problem setting my site to show next search results.

  • August 6, 2010
  • 1 reply
  • 3171 views

Hey everyone. I am having a problem with setting up a next and previous link to show the results from a search engine i made. Also when the next link does show up and i hit it with the results on the page, it resets the whole page. Any idea what i am doing wrong?

===============================================================================================================

<cfparam name="FORM.Islands" default="" />
<cfparam name="URL.StartRow" default="1">

<cfset sNextRow = URL.StartRow + 2 />
<cfset sPreviousRow = URL.StartRow - 2 />

<cfquery name="qResults" datasource="wyi2">
SELECT BusinessID, BusinessName, Address, IslandID, Phone, WebID
FROM Business
WHERE IslandID = <cfqueryparam value="#FORM.Islands#">
ORDER BY BusinessName ASC
</cfquery>

<cfquery name="qIslands" datasource="wyi2">
SELECT IslandID, IslandName
FROM Islands
ORDER BY IslandName ASC
</cfquery>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Where Ya Is :.</title>
<link href="../css/wyi.css" rel="stylesheet" type="text/css" />
</head>

<body>
<!--- Start Div container --->
  <div id="Container">
  <!--- Start div banner --->
    <div id="sBanner">
    <img src="../images/logo_Store_Sales.jpg" width="400" height="175" border="0" usemap="#Map" />
    <map name="Map" id="Map">
      <area shape="rect" coords="220,153,268,169" href="../index.cfm" target="_self" alt="Home" />
      <area shape="rect" coords="287,152,373,168" href="../contact/index.cfm" target="_self" alt="Contact Us" />
    </map>
    </div>
  <!--- End div banner --->
  <!--- Start Search form --->
    <div id="sForm">
      <cfform action="#CGI.SCRIPT_NAME#" method="post" preservedata="yes">
        <table width="400" border="0" cellspacing="2" cellpadding="0">
            <tr>
              <td>
              <cfselect name="Islands"
                        query="qIslands"
                        display="IslandName"
                        value="IslandID"
                        queryPosition="below">
                <option value="all">Please select an island</option>
              </cfselect>
            </td>
              <td>
                <cfinput type="submit" name="Find_btn" class="button" value="Find store" />
               </td>
          </tr>
        </table>
      </cfform>
    </div>
  <!--- End Search form --->
  <!--- Start Results section --->
    <div id="sResults">

      <table border="0" cellpadding="0" cellspacing="2">
        <tr>
          <td colspan="3">
            <cfif IsNumeric(FORM.Islands)>
              <cfoutput>
                We have found #qResults.RecordCount# store<cfif (qResults.RecordCount GT 1) OR (qResults.RecordCount LT 1)>s</cfif>.
              </cfoutput>
            <cfelse>
              Please select an island to help us find the store you are looking for.
            </cfif>
          </td>
        </tr>
        <tr>
          <td> </td>
          <td> </td>
          <td> </td>
        </tr>
        <cfif qResults.RecordCount GT 2>
        <cfoutput>
        <tr>
          <td width="150">
            <cfif URL.StartRow GT 2>
            <a href="#CGI.SCRIPT_NAME#?StartRow=#sPreviousRow#">Previous</a>
          </cfif>
          </td>
          <td width="150">
            <a href="#CGI.SCRIPT_NAME#?StartRow=#sNextRow#">Next</a>
          </td>
          <td> 
           
          </td>
        </tr>
        </cfoutput>
      </cfif>
            <cfoutput query="qResults" startrow="#URL.Startrow#" maxrows="2">
        <tr>
          <td colspan="3">
              <p><a href="results.cfm?BusinessID=#BusinessID#">#BusinessName#</a></p>
          </td>
        </tr>
            </cfoutput>
        <tr>
          <td colspan="2"> </td>
          <td> </td>
        </tr>
        <tr>
          <td colspan="3">Copyright 2010,&copy; Where ya is, All Rights Reserved</td>
        </tr>
      </table>
    </div>
   <!--- End Results section --->
   <!--- Start Advertising --->
    <div id="Advert">
      <img src="../images/ad_sample.jpg" width="200" height="200" />
    </div>
  <!--- End Advertising --->
</div>
<!--- End Div container --->
</body>
</html>

=============================================================================================================

This topic has been closed for replies.
Correct answer JR__Bob__Dobbs

Thank you that fixed it. I have one more question. When i hit "Next" the form doesn't hold it's value, meaning the form resets, but the search results and the next/previous links are still there. Any idea on how i can fix that?


Any information that needs to be retained will need to be sent in one of the following places.

1. A query string in a URL.

2. A form variable

3. A cookie

4. A session variable.

Bear in mind that form and URL variables only exist for a single page request. If you want to "remember" them you will need to submit them again.

You may find this useful.

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0c35c-7ffb.html

1 reply

Inspiring
August 6, 2010

When the next link is clicked and the page requested the second time the value of form.Islands is defaulting to an empty string.  Try passing the Islands variable in the url scope as a start.

August 6, 2010

thx for the reply. Sorry for being a newb, but i have been out of the CF loop for about 5 yrs and alot of what i'm doing now is from looking online and asking forums such as this one. Would you mind taking my code and showing me what i need to change? I tried the following, but no go..

i added a <cfparam name="URL.IslandID" default="" /> to the top of the code.

I also changed the "next" and Previous" string to...

<a href="#CGI.SCRIPT_NAME#?IslandID=#FORM.Islands#&StartRow=#sPreviousRow#">Previous</a>

<a href="#CGI.SCRIPT_NAME#?IslandID=#FORM.Islands#&StartRow=#sNextRow#">Next</a>

Again the form resets. Can't seem to get the form to keep it's value or the search results even after i click the "next" link.

Inspiring
August 6, 2010

You'll need to modify your qResults query to use either a url or form parameter in the where clause to re-run the query each page request using the island value you want to work with.