4 Replies Latest reply on Apr 6, 2007 1:24 PM by Newsgroup_User

    passing variables from pg.A to pg.B then pgC

    welsh15soccer
      I am new to coldfusion but have coding background.
      So I have a Criteria.cfm page, you can search the db by certain criteria(dd lists) and can also have the results sorted(radio buttons) by certain criteria.
      This info is then sent to Report.cfm page and displayed on the screen , from the Report.cfm page
      I must send all the info shown on the page to excel.cfm that opens up in excel.xls. The problem is not sending to excel, the problem is it is not displaying the right information it is just displaying all records from the database.

      How can I get excel.cfm to get the variables/info displayed from Report.cfm?
      I'm super confused, I am looking for some help, bc i am just took over for a guy that coded this whole project.

      Any help would be greatly appreciated!


      Excel.cfm
      <cfparam name="PageNum_Report" default="1">
      <CFQUERY name="Excel_Report" datasource="AMREP">
      SELECT *
      FROM qryReport

      </cfquery>

      <cfset MaxRows_Report=100>
      <cfset StartRow_Report=Min((PageNum_Report-1)*MaxRows_Report+1,Max(Excel_Report.RecordCount,1))>
      <cfset EndRow_Report=Min(StartRow_Report+MaxRows_Report-1,Excel_Report.RecordCount)>
      <cfset TotalPages_Report=Ceiling(Excel_Report.RecordCount/MaxRows_Report)>

      <cfheader name="Content-Disposition" value="inline;filename=excel.xls">
      <cfcontent type="application/msexcel">

      <cfoutput>
      <table width="907" border="1" cellpadding="1" cellspacing="1" bordercolor="##999999" cols="4" style="font:Arial, Helvetica, sans-serif; font-size:14px;">
      <tr bgcolor="##FFFFFF">
      <td width="91" height="32"><div align="center"><strong></strong></div></td>
      <td width="80"><div align="center"><strong></strong></div></td>
      <td width="80"><div align="center"><strong></strong></div></td>
      <td width="115"><div align="center"><strong></strong></div></td>
      <td width="85"><div align="center"><strong></strong></div></td>
      <td width="110"><div align="center"><strong>InputDate</strong></div></td>
      <td width="150"><div align="center"><strong>PlannedOutputDate</strong></div></td>
      <td width="150"><div align="center"><strong>RevisedOutputDate</strong></div></td>
      </tr>
      </cfoutput>

      <cfoutput query="Excel_Report" startRow="#StartRow_Report#" maxRows="#MaxRows_Report#">
      <tr><tr style=" background-color:###iif(currentrow MOD 2,DE('eeeeee'),DE('ffffff'))#;" class="tabletext">
      <td><div align="center" class="style19"><span class="style20">#Excel_Report.info here#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#Excel_Report.info here#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#Excel_Report.info here#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#Excel_Report.info here#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#Excel_Report.info here#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#DateFormat(Excel_Report.InputDate, 'dd mmmm yyyy')#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#DateFormat(Excel_Report.PlannedOutputDate, 'dd mmmm yyyy')#</span></div></td>
      <td><div align="center" class="style19"><span class="style20">#DateFormat(Excel_Report.RevisedOutputDate, 'dd mmmm yyyy')#</span></div></td>
      </cfoutput>
      </table>
      ************************************************************************

        • 1. Re: passing variables from pg.A to pg.B then pgC
          Level 7
          you can pass variables between pages in a number of ways, of which FORM
          and URL scopes are most common. Other possible ways include SESSION,
          APPLICATION and CLIENT scopes, as well as cookies, and you could also
          write the vars to a file on the server and have the other page read them
          from it...

          in your particular case, i would probably use SESSION or FORM scope
          variables:

          on the report page, which presumably receives all selected criteria from
          the criteria.cfm page as a form submission (= FORM scope), populate a
          scructure inside the SESSION scope with the received variables. then on
          the excel.cfm page you can access that structure and retrieve the vars
          to use in the queries. alternatively, instead of creating a SESSION
          scope structure, re-create a form from the criteria.cfm page setting all
          fields to type=hidden, and on clicking a "save as excel file", or
          whatever link users have to click to get the excel report, submit this
          hidden form to excel.cfm page. on that page get the vars out of FORM
          scope and use in your queries.



          --
          Azadi Saryev
          Sabai-dee.com
          Vientiane, Laos
          http://www.sabai-dee.com
          • 2. Re: passing variables from pg.A to pg.B then pgC
            welsh15soccer Level 1
            thanks for the info, but do you have any examples of code. I am going crazy over this.
            • 3. Re: passing variables from pg.A to pg.B then pgC
              Level 7
              welsh15soccer wrote:
              > thanks for the info, but do you have any examples of code. I am going crazy over this.

              on the report.cfm page, at the very top (before any other code) add
              something like:

              <cflock scope="session" type="exclusive" timeout="30">
              <cfloop list="#form.fieldnames#" index="fieldname" delimiters=",">
              <cfset session.searchform["#fieldname#"] = form["#fieldname#"]>
              </cfloop>
              </cflock>

              in the excel.cfm page you will then use
              #session.searchform.fieldnameyouwanttouse# in your queries.
              the queries there are, presumably, same as on the report.cfm page. so
              you should easily port them over to excel.cfm, just instead of
              #form.thisorthat# in them use #session.searchform.thisorthat#

              --
              Azadi Saryev
              Sabai-dee.com
              Vientiane, Laos
              http://www.sabai-dee.com
              • 4. Re: passing variables from pg.A to pg.B then pgC
                Level 7
                welsh15soccer wrote:
                > thanks for the info, but do you have any examples of code. I am going crazy over this.

                oh, don't forget to enable sessionmanagement in your Application.cfm|cfc
                if it is not already enabled... otherwise you have no SESSION scope
                available to you....

                --
                Azadi Saryev
                Sabai-dee.com
                Vientiane, Laos
                http://www.sabai-dee.com