10 Replies Latest reply on Aug 11, 2010 7:33 AM by K0rrupt

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

    K0rrupt Level 1

      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>

       

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

        • 1. Re: Having a problem setting my site to show next search results.
          JR "Bob" Dobbs Level 4

          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.

          • 2. Re: Having a problem setting my site to show next search results.
            K0rrupt Level 1

            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.

            • 3. Re: Having a problem setting my site to show next search results.
              JR "Bob" Dobbs Level 4

              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.

              • 4. Re: Having a problem setting my site to show next search results.
                K0rrupt Level 1

                I think i understand what you are saying, but don't know how to do that. Would you mind showing me?

                • 5. Re: Having a problem setting my site to show next search results.
                  JR "Bob" Dobbs Level 4

                  Something along the lines of:

                   

                   

                   

                  <cfif IsDefined("form.islands")>
                      <cfset searchValue=form.islands />
                  <cfelseif IsDefined("url.islands">
                      <cfset searchValue="url.islands />
                  </cfif>

                   

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

                   

                  You will need to include the searchValue as a query string parameter (url.islands) in your previous/next links.

                  1 person found this helpful
                  • 6. Re: Having a problem setting my site to show next search results.
                    K0rrupt Level 1

                    Thx, but when i added the code you provided the entire form resets and the results are gone. Here's the code again with the updates.

                     

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

                     

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

                     

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

                     

                    <cfif IsDefined("FORM.Islands")>
                      <cfset SearchValue = FORM.Islands />
                    <cfelseif IsDefined("URL.Islands")>
                      <cfset SearchValue = URL.Islands />
                    </cfif>

                     

                    <cfquery name="qResults" datasource="wyi2">
                    SELECT BusinessID, BusinessName, Address, IslandID, Phone, WebID
                    FROM Business
                    WHERE IslandID = <cfqueryparam value="#SearchValue#">
                    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#?IslandID=#FORM.Islands#&SearchValue=#URL.Islands#&StartRow=#sPrev iousRow#">Previous</a>
                              </cfif>
                              </td>
                              <td width="150">
                                <a href="#CGI.SCRIPT_NAME#?IslandID=#FORM.Islands#&SearchValue=#URL.Islands#&StartRow=#sNext Row#">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<br/><br/><cfoutput>#DateFormat(Now())#</cfoutput></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>

                    • 7. Re: Having a problem setting my site to show next search results.
                      JR "Bob" Dobbs Level 4

                      If a CFPARAM for form.islands is included the searchValue variable will be empty when the next/previous links are clicked, since url.islands value will never be used.

                      1 person found this helpful
                      • 8. Re: Having a problem setting my site to show next search results.
                        K0rrupt Level 1

                        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?

                        • 9. Re: Having a problem setting my site to show next search results.
                          JR "Bob" Dobbs Level 4

                          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

                          • 10. Re: Having a problem setting my site to show next search results.
                            K0rrupt Level 1

                            Thanks again for all your help. everything works prefectly now.