Running a query with multiple lists

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Running a query with multiple lists

    Any help would be so appreciated, I have beat my head against the wall on this
    one and have scoured the web trying to find an answer. I am trying to build an
    email program for a client that will allow them to issue press releases. The
    trick is that they need to be able not only to select multiple counties in the
    state, but then they need to select what type of media they send it to (also
    multiple media oultets). NOTE my state has 95 counties, and there are 3 press
    outlets, web, print and radio/ tv. I can use radio buttons for the press
    outlets, and build a query using the ifDefined then and use OR in the query,
    but how can I pass a list to a query? I think that the query should look
    something like this <cfquery name'PressRelease' datasource='name'> SELECT
    Name, EmailAddress From PressReleaseEmail WHERE County = XXXXXXXXXXXX AND
    MediaType = <cfif isDefined ('Form.Print')> '#Form.Print#' <else> NULL
    </cfif> <cfif isDefined ('Form.WEB')> OR '#FORM.WEB#' <esle> NULL </cfif> <cfif
    isDefined ('Form.Radio')> OR '#Form.Radio#' <else> NULL </cfif> So the query
    can be dynamically built from the radio buttons. but how does do I pass the
    list from FORM.County into the query? All help will be wonderful. Andy

    brokerandy25 Guest

  2. Similar Questions and Discussions

    1. writing content of multiple lists to db
      I have a time reporting app that contains five elements, staff, date, CR (job) category (activity) and hrs. Since each staff person can work...
    2. 'or' selection from multiple lists
      Hey, I am trying to set up a selection where a user can choose from one or multiple drop downs and choose as many within a box as they want. ...
    3. Problem combing multiple lists into one
      I have three lists (m1,m2,m3) and I need to combine them into one list (m4): <cfset m1 = valuelist(search2.cat)> <cfset m2 =...
    4. CAML Query: Multiple Query Fields Issue
      I need to Create a CAML Query Dynamically with VB to a Sharepoint WebService GetListItems Method. The User Could Select 1 to X Number of IDs...
    5. dropdown lists - query parameter error
      Hi, I'm using the following for 2 dropdown boxes in asp.net. The first is the basis for the contents of the second. First works fine, then on...
  3. #2

    Default Re: Running a query with multiple lists

    Hope it helps. I m pretty sure it will work if u play around a bit, in case of
    any errors.:beer;

    <!--- assuming u are using multiple select box which names Counties
    <cfselect name="Counties" multiple="Yes">
    <cfoutput query="allCounties">
    <option value="countyname">#countyname#</option>
    </cfoutput>
    </cfselect>

    --->
    <!--- when u submit the form above, u will have a values (as list) in
    form.Counties
    which should look like this a,b,c,d,e,f u can check it by using
    <cfoutput>#form.Counties#</cfoutput> --->

    <!--- please note the variable below 'CountyName', will become the list
    element. so, it will run the query
    and compare the value one by one, eg. first a, then b, then c and so on. --->
    <cfloop index="CountyName"
    list="#form.Counties#">

    <cfquery name"PressRelease" datasource="name">
    SELECT Name, EmailAddress From PressReleaseEmail WHERE
    County = #CountyName# AND MediaType =
    <cfif isDefined ('Form.Print')>
    '#Form.Print#'
    <else>
    NULL
    </cfif>
    <cfif isDefined ('Form.WEB')>
    OR '#FORM.WEB#'
    <esle>
    NULL
    </cfif>
    <cfif isDefined ('Form.Radio')>
    OR '#Form.Radio#'
    <else>
    NULL
    </cfif>
    </cfquery>
    </cfloop>

    Maneesh Tikkiwal Guest

  4. #3

    Default Re: Running a query with multiple lists

    I knew I had to loop through the query, just couldn't figure out the syntax,
    you are a life saver. Some times the simplest answers are the hardest to find
    .. . . . . do I have to use the cfselect tag or can I use the html select tag?

    brokerandy25 Guest

  5. #4

    Default Re: Running a query with multiple lists

    no worries.

    it doesn't matter what u use, cfselect or html select. both will give u the desired result.
    Maneesh Tikkiwal Guest

  6. #5

    Default Re: Running a query with multiple lists

    CFLOOP surrounding the query is kind of inefficent.

    What about using SQL's IN statement which repsents an OR list
    You could do this

    <!---- surrounds each country with single quote for SQL ---->
    <cfset lstCountries = chr(34) & Replace(FORM.Countries, ',', chr(34) & ","
    chr(34), All) & chr(34) >

    <cfquery name"PressRelease" datasource="name">
    SELECT Name, EmailAddress From PressReleaseEmail
    WHERE County IN(#PreserveSingleQuotes(lstCountries)#)

    AND MediaType =
    <cfif isDefined ('Form.Print')> '#Form.Print#' <else> NULL </cfif>
    <cfif isDefined ('Form.WEB')> OR '#FORM.WEB#' <esle> NULL </cfif>
    <cfif isDefined ('Form.Radio')> OR '#Form.Radio#' <else> NULL </cfif>
    </cfquery>

    I think ASCII code 34 is the ' sign, this works in SQL Server, don't do much
    with Access but it should support the IN command and you would of course use
    double quotes.

    This way you don't potentially open 95 select statements on the server.

    "Maneesh Tikkiwal" <webforumsuser@macromedia.com> wrote in message
    news:d48hon$i5o$1@forums.macromedia.com...
    > no worries.
    >
    > it doesn't matter what u use, cfselect or html select. both will give u
    > the desired result.

    Adam 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