Topic: Maintaining Variables


envidobi    -- 01-06-2004 @ 3:58 PM
  I have a search page that i pass 3 variables from. The results page calls these as 3 CFPARAM variables, and gives the results depending on the variables. I would like to Sort my results using the Tutorial with the CFSWITCH in the Query, but i lose all the variable information when the page reloads after being requested to sort. Anyone have any suggestions?

Envi

"Lifes what happens when you making other plans" - John Lennon


donli    -- 01-06-2004 @ 9:41 PM
  See if the following BLOCK of code give you some idea.

-- start
<!-- display jobs for edit selection -->
  <cfparam name="sorta" default="j.jobname">
  <cfif isdefined("URL.sort")>
       <cfset sorta = URL.sort>
  </cfif>
  
  <cfquery name="getJobs" datasource="#session.xxxds#">
    select j.jobID, j.jobname, j.jobdescription, cus.customername, c.community
       from jobticket j, customers cus, communities c
       where j.customersID = cus.customersID
                      and cus.communityID = c.communityID
                      and j.jobcomplete = 0     
       order by #sorta#               
  </cfquery>

<tr>
<cfoutput>
        <td><a href="#CGI.script_name#?sort=j.jobname¬ManyJobs=true"><b>Job name</b></a></td>
                 <td width="10"></td>
                 <td><b>Job note</b> ...</td>  
                 <td width="10"></td>
                 <td><a href="#CGI.script_name#?sort=cus.customername¬ManyJobs=true"><b>Customer</b></a></td>
                 <td width="10"></td>
                 <td><a href="#CGI.script_name#?sort=c.communityID¬ManyJobs=true"><b>Community</b></a></td>
</cfoutput>     
</tr>

-- end

Don Li

a MUST-HAVE for MS SQL Server database --
http://webforums.macromedia.com/coldfusion/messageview.cfm?catid=14&threadid=751833

http://www.hegelsoftware.com/regURL.htm


envidobi    -- 01-07-2004 @ 6:15 AM
  I'm not really having a problem with the sort part par se. The CFSWITCH works perfect, with exception to the variables have been passed to the page that filter the query. For example, the sort will work perfect in the event that all the records are displayed, however if i had some variable like a search term passed through to filter, when i click sort the page reloads not remembering the original keyword that was sent as a variable from the search page. So, from using this tutorial http://tutorial168.easycfm.com/, it should be something like
<cfoutput>
<tr bgcolor="##E5E5E5"><!--- Header Row --->
<td><a href="movies.cfm?sort=#IIF(sort is 1, '2', '1')# & Searchterm=#searchterm# & Searchtype=#searchtype#">Movie Title</a></td>




I don't know if that is correct or not, but thats the idea of it. Know any other ways?

Envi

"Lifes what happens when you making other plans" - John Lennon


donli    -- 01-07-2004 @ 1:42 PM
  Run debug at the TOP of THE movies.cfm script to see the value of URL variables of sort, searchTerm and searchType.

Don Li


http://www.hegelsoftware.com/regURL.htm


envidobi    -- 01-07-2004 @ 3:57 PM
  I have my debuggin turned on all the type in development. The values are always what's been chosen correctly, however the problem seems to lie in the page that is being asked to sort. 1st page is the search that i send the orginal variables, then the results page has the variables applied to the query (ex. maybe i'm just typed in the word "chris") then if i want to sort the column, the status bar will show all the correct variables being passed to the same page when it reloads as URL variables now rather than form variables. I have tried to do an if statement that would look for URL variables and cfparam set the variables if URL.Sort has been found, but no luck. So again the problem seems to be setting variables on reloading the page cuz the URL variables when asking for the sort shows the values i want, but the reloaded page doesn't seem to know that they need to be applied just like the original form fields.

Envi

"Lifes what happens when you making other plans" - John Lennon


envidobi    -- 01-13-2004 @ 2:23 PM
  Can anyone help me with this?

Envi

"Lifes what happens when you making other plans" - John Lennon


CJ    -- 01-13-2004 @ 3:02 PM
  perhaps you can post some code from the page that's giving you trouble?



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com


envidobi    -- 01-13-2004 @ 4:53 PM
  Variables start here with the query

   <cfif isdefined ("URL.Sort")>
          <cfparam name="URL.search_category">
          <cfparam name="URL.searchterm">
          <cfelse>
          <cfparam name="form.search_category" default="Types">
          <cfparam name="form.searchterm" default="-">
          <cfif form.searchterm eq "">
            <cfset form.searchterm = "-">
          </cfif>
          <cfparam name="sort" default="1">
        </cfif>
        <!--- If Types is the category, then show grouped by types --->
        <cfif #form.search_category# eq "Types">
          <!--- Query for Production Types - Release companies marked as "Yes" Only --->
          <cfquery name="q_results" datasource="#datasource#" dbtype="ODBC">
    SELECT Productions.ProductionID, Productions.ProductionTitle, Contacts.Business, J_Production_Companies.Released, Productions.ProductionYear, Production_Types.ProductionType, Production_Group_Types.ProductionGroupName, Productions.Description FROM (Production_Types INNER JOIN (Production_Group_Types INNER JOIN Productions ON Production_Group_Types.ProductionGroupID = Productions.ProductionGroup) ON Production_Types.ProductionTypeID = Productions.ProductionType) INNER JOIN (Contacts INNER JOIN J_Production_Companies ON Contacts.ContactID = J_Production_Companies.ContactID) ON Productions.ProductionID = J_Production_Companies.ProductionID
    <cfif #form.searchterm# neq "-">
      WHERE ((ProductionTitle like '%#searchterm#%') OR (Description like '%#searchterm#%')) AND (((J_Production_Companies.Released)<>No))
                  <cfelse>
      WHERE (((J_Production_Companies.Released)<>No))
    </cfif>
    ORDER BY Production_Types.ProductionType asc,
    <cfswitch expression="#sort#">
      <cfcase value="1">
      Productions.ProductionTitle asc, Productions.ProductionYear asc
      </cfcase>
      <cfcase value="2">
      Productions.ProductionTitle desc, Productions.ProductionYear
      </cfcase>
      <cfcase value="3">
      Productions.ProductionYear asc, Productions.ProductionTitle asc
      </cfcase>
      <cfcase value="4">
      Productions.ProductionYear desc
      </cfcase>
      <cfcase value="5">
      Contacts.Business, Productions.ProductionTitle, Productions.ProductionYear
      </cfcase>
      <cfcase value="6">
      Contacts.Business desc, Productions.ProductionTitle, Productions.ProductionYear
      </cfcase>
      <cfcase value="7">
      Production_Group_Types.ProductionGroupName, Productions.ProductionTitle, Productions.ProductionYear
      </cfcase>
      <cfcase value="8">
      Production_Group_Types.ProductionGroupName desc, Productions.ProductionTitle, Productions.ProductionYear
      </cfcase>
    </cfswitch>
          </cfquery>


i use them here:

          <cfif q_results.recordcount gt 0>
            <tr align="left"> <cfoutput>
                <th align="left" class="FieldTitle">Production Title?sort=#IIF(sort is 1, '2', '1')#&search_category=#form.search_category#&search_term=#form.search_term#></th>
                <th align="left" class="FieldTitle">Release Year</th>
                <th align="left" class="FieldTitle">Releasing Company</th>
                <th align="left" class="FieldTitle">Production Group Type</th>
            </cfoutput> </tr>


I only did the first one as to show how i don't understand how to pass the variables. I mean in the status bar i will see the correct names to be passed after the sort, but they don't get taken when the page reloads. THanks for checking it out CJ!
Appreciate it! Smile

Envi

"Lifes what happens when you making other plans" - John Lennon


CJ    -- 01-13-2004 @ 5:02 PM
  first, take your <cfparam> tags out of the <cfif isDefined()> block.  Well, just remove the <cfif></cfif>.  the default behaviour of <cfparam> is to say, "if this variable is not defined, create it and assign it -this- value".

that was the first thing i noticed...and as i'm pressed for time, going to ask you to make that change, and report back whether or not it fixes anything Smile  



-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com


envidobi    -- 01-13-2004 @ 6:05 PM
  still no change... the sort works with setting a default but i need to it be able to sort a filtered query. When i mouse over the link and look at the attributes in the task bar all i see is my default settings that will be passed over to the next sort request.
This is what i have right now:

<cfparam name="URL.search_category" default="Types">
          <cfparam name="URL.searchterm" default="-">
          <cfparam name="form.search_category" default="Types">
          <cfparam name="form.searchterm" default="-">
          <cfif form.searchterm eq ""><cfset form.searchterm = "-"></cfif>
          <cfparam name="sort" default="1">

        <!--- If Types is the category, then show grouped by types --->
        <cfif #form.search_category# eq "Types">
          <!--- Query for Production Types - Release companies marked as "Yes" Only --->
          <cfquery name="q_results" datasource="#datasource#" dbtype="ODBC">
               SELECT Productions.ProductionID, Productions.ProductionTitle, Contacts.Business, J_Production_Companies.Released,
               Productions.ProductionYear, Production_Types.ProductionType, Production_Group_Types.ProductionGroupName, Productions.Description
               FROM (Production_Types
               INNER JOIN (Production_Group_Types
               INNER JOIN Productions
               ON Production_Group_Types.ProductionGroupID = Productions.ProductionGroup)
               ON Production_Types.ProductionTypeID = Productions.ProductionType)
               INNER JOIN (Contacts
               INNER JOIN J_Production_Companies
               ON Contacts.ContactID = J_Production_Companies.ContactID)
               ON Productions.ProductionID = J_Production_Companies.ProductionID
               <cfif #form.searchterm# neq "-">
                 WHERE ((ProductionTitle like '%#searchterm#%') OR (Description like '%#searchterm#%'))
                 AND (((J_Production_Companies.Released)<>No))
               <cfelse>
                 WHERE (((J_Production_Companies.Released)<>No))
               </cfif>
               ORDER BY Production_Types.ProductionType asc,
               <cfswitch expression="#sort#">
                 <cfcase value="1">
                 Productions.ProductionTitle asc, Productions.ProductionYear asc
                 </cfcase>
                 <cfcase value="2">
                 Productions.ProductionTitle desc, Productions.ProductionYear
                 </cfcase>
                 <cfcase value="3">
                 Productions.ProductionYear asc, Productions.ProductionTitle asc
                 </cfcase>
                 <cfcase value="4">
                 Productions.ProductionYear desc
                 </cfcase>
                 <cfcase value="5">
                 Contacts.Business, Productions.ProductionTitle, Productions.ProductionYear
                 </cfcase>
                 <cfcase value="6">
                 Contacts.Business desc, Productions.ProductionTitle, Productions.ProductionYear
                 </cfcase>
                 <cfcase value="7">
                 Production_Group_Types.ProductionGroupName, Productions.ProductionTitle, Productions.ProductionYear
                 </cfcase>
                 <cfcase value="8">
                 Production_Group_Types.ProductionGroupName desc, Productions.ProductionTitle, Productions.ProductionYear
                 </cfcase>
               </cfswitch>
          </cfquery>

            <tr>
            <td colspan="4" align="left"  class="BaseText"> <cfoutput> Found #q_results.recordcount#
               <cfif q_results.recordcount eq 1>instance<cfelse>instances</cfif>
                  <cfif searchterm neq "-">of #form.searchterm#</cfif>that relate to #form.search_category#</cfoutput><br>
                </td>
          </tr>

          <cfif q_results.recordcount gt 0>
            <tr align="left"> <cfoutput>
                <th align="left" class="FieldTitle"><a href="production_results.cfm?sort=#IIF(sort is 1, '2', '1')#&search_category=#form.search_category#&searchterm=#form.searchterm#">Production Title</a></th>
                <th align="left" class="FieldTitle">Release Year</th>
                <th align="left" class="FieldTitle">Releasing Company</th>
                <th align="left" class="FieldTitle">Production Group Type</th>
            </cfoutput> </tr>


if i take out the defaults i get an error telling me that the URL variables don't exist and must in order to process the page. The variables coming from the form must be in place for the first set of results (filtered with a search category and/or searchterm or not)to exist. Then, for the sort functionality, there has to be a way to pass on the form variables which then become url variables. I'm new to programming entirely so alot of this is hypothetical to me Smile . I thank you again for you help and patience on this!


Envi

"Lifes what happens when you making other plans" - John Lennon


EasyCFM.COM ColdFusion Forums : http://archive.easycfm.com/forums
Topic: http://archive.easycfm.com/forums/viewmessages.cfm?Forum=12&Topic=2629