SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: passing variables

  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing variables

    hi! i am writing a search page that has 3 components. 1-the initial search page where you select a few things, then there are checkboxes to determine what is on the next page. 2-a second search page which has the values from the first, and then other more specific search criteria. 3-a results page, displaying the results of the query based on the variables from both prior pages.

    my problem is this: how do i get the values of the first 3 variables from page 1 to go through to page 3?

    does this make sense? i have tried hidden variables, but don't understand them enough to make them work.

    thanks! lb

  2. #2
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oooh, sounds like fun

    ill write up an example of this 2nite when i get home

  3. #3
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks--quick question: how do you pass a hidden variable that has a value of a variable?

    ex: <cfset Audience = Aud_Select>

    want to pass Audience to the next page. like this?

    <input type="hidden" value="#Audience#">

    i'm stuck. Aud_Select is a value from a select list from the first page. on the second page it is displayed as a title. on the third page (results) it needs to be a parameter of the query and then displayed.

    ugh.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2000
    Location
    Yeppoon, Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you pass a hidden variable that has a value of a variable?
    If you have Aud_Select as a variable from a previous page and it is sent from a form it is qualified as a form variable. You don't actually need this CFset line at all, you can reference the variable directly.

    delete this line !---<cfset Audience = Aud_Select> --->

    This line will pass a hidden variable named audience to the next page with the value of Aud_Select that was passed from your select box.
    Code:
    <input type="hidden" name="audience" value="#form.Aud_Select#">
    As for sending data and variables to other pages just keep adding that hidden form variable. If there is no form on the sending page you can send variables via a HTTP query string (ie. http://www.sitepoint.com?variable=va...ondvar=value2, the part after the ? is a query string) and reference the variables in the called page like this url.variable_name

    ie. page is passed variable fred via query string, referenced in CF page with #url.fred#

    All those methods should allow you to send all the variables from page to page no probs .

    - Nathaniel
    Knowledge is knowing that a tomatoe is a fruit; wisdom is not putting it in a fruit salad.

  5. #5
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, did that but it's still not working. on my third page, i have a query that uses the info from the first and second pages.

    <CFQUERY NAME="Results" DATASOURCE="InfoOps">
    SELECT *
    FROM M_PA
    WHERE Event_Num = Event_Num

    <CFIF IsDefined('P_I_N')>
    <CFIF P_I_N IS NOT "">
    <CFIF P_I_N IS 1>
    AND P_I_N = 'Prospect'
    <CFELSEIF P_I_N IS 2>
    AND P_I_N = 'Influencer'
    <CFELSEIF P_I_N IS 3>
    AND P_I_N = 'Neutral'
    </CFIF>
    </CFIF>
    </CFIF>

    <CFIF IsDefined('Ethnic')>
    <CFIF Ethnic IS NOT "">
    AND Ethnic LIKE '#Ethnic#'
    </CFIF>
    </CFIF>

    <CFIF IsDefined('Audience')>
    <CFIF Audience IS NOT "">
    AND Audience LIKE '#Audience#'
    </CFIF>
    </CFIF>

    etc., etc. a bunch more cfif's

    the lines where i have AND Ethnic LIKE '#Ethnic#', etc. are not working. help! i don't know if this makes any sense to someone else.

    thanks

  6. #6
    SitePoint Zealot
    Join Date
    Jun 2000
    Location
    Yeppoon, Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, did that but it's still not working. on my third page, i have a query that uses the info from the first and second pages.

    <CFQUERY NAME="Results" DATASOURCE="InfoOps">
    SELECT *
    FROM M_PA
    WHERE Event_Num = Event_Num
    I take it the WHERE line above is referencing one of those variables? That being the case you need to tell CF that:

    WHERE Event_Num = #form.Event_Num# or if it was sent via URL
    WHERE Event_Num = #url.Event_Num#

    This referencing helps CF (and you) know where things have come from and can stop clashes in names as url.fred and form.fred are distinct variables. It is also considered good practice

    <CFIF IsDefined('P_I_N')>
    <CFIF P_I_N IS NOT "">
    <CFIF P_I_N IS 1>
    AND P_I_N = 'Prospect'
    <CFELSEIF P_I_N IS 2>
    AND P_I_N = 'Influencer'
    <CFELSEIF P_I_N IS 3>
    AND P_I_N = 'Neutral'
    </CFIF>
    </CFIF>
    </CFIF>

    <CFIF IsDefined('Ethnic')>
    <CFIF Ethnic IS NOT "">
    AND Ethnic LIKE '#form.Ethnic#'
    </CFIF>
    </CFIF>

    <CFIF IsDefined('Audience')>
    <CFIF Audience IS NOT "">
    AND Audience LIKE '#form.Audience#'
    </CFIF>
    </CFIF>

    When you say these aren't working are you getting error messages from CF? If so what are they - CF variable problems or SQL syntax errors (that a probably caused by variable problems).

    Try making sure that they are referenced with the correct type (form, url, cgi, etc...) and make sure that the variables you are trying to use are being passed to the page properly - ie. correct names and they have the expected value. CF has a debugging mode for this (which I have never used) or you can just put the classic <CFOUTPUT> tag somewhere and spit 'em all out and see what's happening. use CF_NUM_RESULTS ???? or whatever it is, I can't remember, to check the number of records returned by the query.

    Lastly, make sure that you've closed your CFQUERY tag
    Knowledge is knowing that a tomatoe is a fruit; wisdom is not putting it in a fruit salad.

  7. #7
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    didnt know that it was CF, damn you

  8. #8
    SitePoint Zealot
    Join Date
    Jun 2000
    Location
    Yeppoon, Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I too first assumed PHP after the first post

    As an aside I found the tutorial installed with the CF manual to be EXTREMELY helpful in learning CF. It is highly recommended when getting started.
    Knowledge is knowing that a tomatoe is a fruit; wisdom is not putting it in a fruit salad.

  9. #9
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope, it's in cold fusion--sorry. and i'm not really just learning cold fusion. i actually have a search page that is working that uses 2 pages, i was just trying to make it more complex and user-friendly by breaking it up into 3 pages.

  10. #10
    SitePoint Zealot
    Join Date
    Jun 2000
    Location
    Yeppoon, Australia
    Posts
    186
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how are the changes going? Are the errors continuing? Is the site available to the web so we can have a look at the errors or bugs to get a better idea of the what's not quie right.
    Knowledge is knowing that a tomatoe is a fruit; wisdom is not putting it in a fruit salad.

  11. #11
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unfortunately, it's not a live site at this point. i have somewhat given up on this...for now! i will try again next week. perhaps if someone could try to create a play one for me? here's the lowdown on what i need:

    1-search page with 3 fields: a checkbox group of 3, and 2 select lists that are populated by the database.
    a group of checkboxes that determines what the user will search on the next page.

    2-2nd search page with the first 3 fields written out, and whatever search functions the user chose on the page before.

    3-results page whose query uses the fields from both pages.

    thanks!

  12. #12
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This shouldn't be that hard. We'll do it a step at a time. Hopefully, others will take care of some steps for me as I can't do them all. Just let us know when you need to start coding again.

    BTW, sometimes taking breaks is the easiest way to solve a problem.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •