5 Replies Latest reply on Jul 7, 2006 11:38 PM by richy2424

    session max from query

    richy2424
      Hi i have the query below which is ok, but i need to have a default value for SESSION.year5, the problem i have is i need the default vale to be "MAX GetResults.MR.Season" not sure how to enter this into my code, do i add it to the cfparam default or efelse the session

      <cfparam name="SESSION.TeamName5" type="string" default="">
      <cfparam name="SESSION.Year5" type="string" default="">

      <cfif isdefined ("FORM.Years")>
      <cfset SESSION.Year5 = FORM.Years>
      </cfif>

      <cfquery name="GetResults" datasource="Cricket">
      SELECT *
      FROM matchresults MR

      INNER JOIN
      TeamNames TN
      ON MR.TeamID = TN.ID

      INNER JOIN
      SeasonTable ST
      ON MR.Season = ST.SeasonID

      WHERE
      0=0
      <CFIF SESSION.TeamName5 IS NOT "">
      AND
      (MR.TeamID = '#SESSION.TeamName5#')</CFIF>
      <CFIF SESSION.Year5 IS NOT "">
      AND
      (MR.Season = '#SESSION.Year5#')</CFIF>
      </cfquery>
        • 1. Re: session max from query
          Dan Bracuk Level 5
          If you want to set the session variable to something based on a query result, you have to do so after you run the query. So it certainly won't be in cfparam.

          How you code it depends on what you are trying to do. I notice that it changes if a form variable exists.
          • 2. Re: session max from query
            richy2424 Level 1
            Ok many thanks

            so could i do something like this after the query?


            <cfif isdefined ("FORM.Years")>
            <cfset SESSION.Year5 = FORM.Years>
            <cfelse>
            <cfset SESSION.Year5 = MAX GetResults.MR.Season>
            </cfif>
            • 3. Re: session max from query
              richy2424 Level 1
              Ok many thanks

              so could i do something like this after the query?


              <cfif isdefined ("FORM.Years")>
              <cfset SESSION.Year5 = FORM.Years>
              <cfelse>
              <cfset SESSION.Year5 = MAX GetResults.MR.Season>
              </cfif>
              • 4. Re: session max from query
                Dan Bracuk Level 5
                The syntax is fine. The logic may or may not be, depending on what you want to do. If you step back from your code a bit and describe to yourself in simple English what you want to do, you can then convert that to code.

                • 5. Re: session max from query
                  richy2424 Level 1
                  Ok what i need is set session to form value if defined, if not defined set session to MAX GetResults.MR.Season

                  i have tried the code below but i get this error

                  Invalid CFML construct found on line 37 at column 29.
                  ColdFusion was looking at the following text:
                  GetResults.MR.Season

                  <cfif isdefined ("FORM.Years")>
                  <cfset SESSION.Year5 = FORM.Years>
                  <cfelse>
                  <cfset SESSION.Year5 = MAX GetResults.MR.Season>
                  </cfif>