Dropdown Menu (Noob)

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Dropdown Menu (Noob)

    I have two tables linked together by an ID field. The first table contains
    reviewers. The second table contains reviews. I also have a drop down that I
    want to use. The idea is to select a reviewer, and have their reviews populate
    below. I'm having trouble getting this to happen.

    I have this as my queries:

    <cfquery datasource="mydata" name="getData">
    SELECT *
    FROM reviewers, reviews
    WHERE reviewers.ID = reviews.ID
    </cfquery>

    <cfquery datasource="mydata" name="getReviewers">
    SELECT ID, Reviewer
    FROM reviewer
    ORDER BY reviewer
    </cfquery>

    I have a drop down and it shows all Reviewers like I want it to:

    <form name="form1">

    <script language="JavaScript">
    function MM_jumpMenu(targ,selObj,restore){
    eval(targ+".location='"+"index.cfm?ID="+selObj.opt ions.value+"'");
    if (restore) selObj.selectedIndex=0;
    }</script>

    <select name="menu1" onChange="MM_jumpMenu('parent',this,1)">
    <cfset thisID = ID>
    <cfoutput query="getReviewers">
    <cfif ID eq thisID>
    <option selected value="#ID#">#Reviewer#</option>
    <cfelse>
    <option value="#ID#">#Reviewer#</option>
    </cfif>
    </cfoutput>
    </select>
    </form>

    And then I have this showing the results:

    <cfoutput query="getData" Group="ID">
    #Reviewer#<br>
    <cfoutput>#Review#
    </cfoutput>
    </cfoutput>

    Here's the problem I have. My results show all reviewers on ONE page. The drop
    down selector does nothing. I want to be able to show one reviewer with all
    their reviews below them at a time and the selector to change reviewers.
    :confused;

    USC_ZEUS Guest

  2. Similar Questions and Discussions

    1. List/Menu Form hides dropdown Menu
      http://2006.maximizer.com/about/customers/index.html when you scroll over 'company' in the main navbar at the top of the page, you'll see what...
    2. dropdown menu
      hi everyone, im s student doing an interactive cv as project and would like to have a dropdown menu in the project but all the help files dont...
    3. add the dropdown menu on overlay?
      hello all, i wanna add dropdown menu with lingo or javascrpt on .W3D file on director and i want it on top the .W3D file (overlay). is it possible...
    4. Need Help Using Flash Menu Tempates (noob)
      Ive only worked slightly with flash and web-design in general so im a total n00b at this. Anyways. here's my problem. I can't get any flash movies I...
    5. Horizontal DropDown Menu
      OK, so I am definitely not a guru in writing DHTML JavaScript, and my boss likes the horizontal dropdown menu on the top navigation of...
  3. #2

    Default Re: Querying with a Dropdown

    You have to submit the form to run a query for the selected reviewer.
    Dan Bracuk Guest

  4. #3

    Default Re: Querying with a Dropdown

    <!--- enclose query in an if to make sure that the url.id has been passed
    before the query is executed --->
    <cfif IsDefined("url.ID")>
    <cfquery datasource="mydata" name="getData">
    SELECT *
    FROM reviewers INNER JOIN reviews ON reviewers.ID = reviews.ID
    WHERE reviewers.ID = #url.ID#
    </cfquery>
    </cfif>

    <!--- also enclose the cfoutput until the url.id has been passed --->
    <cfif IsDefined("url.ID")>
    <cfoutput query="getData" Group="ID">
    #Reviewer#<br>
    <cfoutput>#Review#
    </cfoutput>
    </cfoutput>
    </cfif>

    Ken

    The ScareCrow Guest

  5. #4

    Default Re: Querying with a Dropdown

    Thanks ScareCrow. I changed your suggestion what I have below and it works
    like I want it to. I don't really understand how and would like to if anyone
    wants to explain to me.

    <cfif IsDefined("ID")>
    <cfquery datasource="mydata" name="getData">
    SELECT *
    FROM reviewers INNER JOIN reviews
    ON reviewers.ID = reviews.ID
    reviewers.ID = #ID#
    </cfquery>
    </cfif>

    <cfquery datasource="mydata" name="getReviewers">
    SELECT ID, Reviewer
    FROM reviewer
    ORDER BY reviewer
    </cfquery>

    <form name="form1">

    <script language="JavaScript">
    function MM_jumpMenu(targ,selObj,restore){
    eval(targ+".location='"+"index.cfm?ID="+selObj.opt ions.value+"'");
    if (restore) selObj.selectedIndex=0;
    }</script>

    <select name="menu1" onChange="MM_jumpMenu('parent',this,1)">
    <cfset thisID = ID>
    <cfoutput query="getReviewers">
    <cfif ID eq thisID>
    <option selected value="#ID#">#Reviewer#</option>
    <cfelse>
    <option value="#ID#">#Reviewer#</option>
    </cfif>
    </cfoutput>
    </select>
    </form>

    <cfif IsDefined("ID")>
    <cfoutput query="getData" Group="ID">
    #Reviewer#<br>
    <cfoutput>#Review#
    </cfoutput>
    </cfoutput>
    </cfif>

    USC_ZEUS Guest

  6. #5

    Default Re: Querying with a Dropdown

    Okay, an explination.

    But first, I think it's just a typo as you said it works but
    <cfif IsDefined("ID")>
    <cfquery datasource="mydata" name="getData">
    SELECT *
    FROM reviewers INNER JOIN reviews
    ON reviewers.ID = reviews.ID
    reviewers.ID = #ID#
    </cfquery>
    </cfif>

    You don't have the "WHERE" before reviewers.ID = #ID#

    I assume you want the explination for the bold parts ?

    Initially the page loads, as the variable "ID" is not defined any code
    contained in the cfif will not be executed.
    Note: You should scope you variables so "ID" should be "URL.ID"

    Now when the user select an option from the select list, the page is reloaded
    But this time the variable "ID" is defined, so the code in the cfif is
    executed.

    "INNER JOIN" "ON" is a more standards compliant why to join table than using
    the comma and where clause.
    But this is usually a personal preference.

    Ken


    The ScareCrow Guest

  7. #6

    Default Re: Querying with a Dropdown

    I do have a WHERE in there, just a typo indeed. Thanks again.
    USC_ZEUS Guest

  8. #7

    Default Re: Querying with a Dropdown

    Would structkeyexists(url,'ID') be faster than isdefined()?
    Also, safer to scope the search in case there is another var named ID in
    another scope somewhere on the page?
    Also, safer and faster to use WHERE=<cfqueryparam value="#url.ID#"
    cfsqltype="cf_sql_integer">?




    "The ScareCrow" <info@krcaldwell.com> wrote in message
    news:dsdt66$h4i$1@forums.macromedia.com...
    > Okay, an explination.
    >
    > But first, I think it's just a typo as you said it works but
    > <cfif IsDefined("ID")>
    > <cfquery datasource="mydata" name="getData">
    > SELECT *
    > FROM reviewers INNER JOIN reviews
    > ON reviewers.ID = reviews.ID
    > reviewers.ID = #ID#
    > </cfquery>
    > </cfif>
    >
    > You don't have the "WHERE" before reviewers.ID = #ID#
    >
    > I assume you want the explination for the bold parts ?
    >
    > Initially the page loads, as the variable "ID" is not defined any code
    > contained in the cfif will not be executed.
    > Note: You should scope you variables so "ID" should be "URL.ID"
    >
    > Now when the user select an option from the select list, the page is
    > reloaded
    > But this time the variable "ID" is defined, so the code in the cfif is
    > executed.
    >
    > "INNER JOIN" "ON" is a more standards compliant why to join table than
    > using
    > the comma and where clause.
    > But this is usually a personal preference.
    >
    > Ken
    >
    >

    Lossed Guest

  9. #8

    Default Re: Querying with a Dropdown

    I could not tell you if it is faster, but the move is towards using
    structkeyexists instead of isdefined
    and yes, you should be using cfqueryparam
    you will just find people will not include this in their posts as it's quicker
    to just put the var.

    Ken

    The ScareCrow Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139