Searching a column containing a list against a form list

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

  1. #1

    Default Searching a column containing a list against a form list

    I have a form that allows users to select multiple items from a list.

    form.hobbies = 1,5,3,6,8,2 (from a table pullup)
    I want to be able to search a table of users where
    each user has a column of "hobbies" also a list.

    How can my select statement parse the table of
    users and compare and select those users
    who have at least one hobby in their record
    that is in the selected form.hobbies?

    I am a bit braindead on this one :)
    Tx in advance.... I have the CF end
    worked out, just need the SQL portion of it.


    --
    Tami
    aka DixieGal

    **************************
    So it is that the gods to dno give all men gifts of grace - neither good
    looks not intelligence nor eloquence...
    --Homer, The Odyssey
    **************************

    DixieGal Guest

  2. Similar Questions and Discussions

    1. Converting a 3 column pdf address list to a one column MS word doc
      I need to convert a 3 col pdf into a manipulable text doc. Acrobat gives me lots of ways to do this in the normal program, but it doesn't preserve...
    2. Column count for list box won't change
      I'm using a static XML set to populate a list box. Because I want to control which columns (fields) are visible and which rows (records) are...
    3. Searching a list from a list
      Is there an easy way to find a list of phrases in another list of phrases. We have a contact DB in which a field (feywords) stores a comma...
    4. Recursive searching through a list
      Hi there, I need to write a script that will test each item in a list to see if that item is a list. If it is, it should test each item in the...
    5. Multi Column List Box
      Neils, Thank you for your suggestion. The method you mention is completely new to me. I have only recently switched from Paradox to Access. In...
  3. #2

    Default Re: Searching a column containing a list against a formlist

    This isn't a good way to store your data. The best method, from both a data
    modeling and performance perspective, would be to normalize the information.
    You would have three tables:

    USER
    --------------
    UserID
    FirstName
    LastName

    HOBBY
    ------------
    HobbyID
    Title (Programming, Classic Cars, etc)

    USER_HOBBY
    ------------------------
    UserID
    HobbyID

    Each user hobby would be entered as a separate record in the USER_HOBBY table.
    Like this:

    UserID | HobbyID
    ------------------------------
    22 | 1
    22 | 5
    22 | 3
    22 | 6

    ... then to find users with at least one hobby that is in your list, run a
    simple select statement using a where in .... clause

    --- not tested. note - should use cfqueryparam
    SELECT u.UserID, u.FirstName, u.LastName
    FROM User u INNER JOIN User_Hobby uh ON u.UserID = uh.UserID
    WHERE uh.HobbyID IN (#form.hobbies#)



    mxstu Guest

  4. #3

    Default Re: Searching a column containing a list against a formlist

    As mxstu said, your data structure makes it easy to load records, but very
    difficult to use them for anything. But, it you gotta go with what ya got,
    this will work.

    <cfsetting requestTimeout="a very large number">
    <cfloop list="form.hobbies" index = "hobby">
    <cfquery>
    select stuff from tableofusers
    where hobbies like '%#hobby#%'
    </cfquery>
    something to store results so far.
    </cfloop>


    Originally posted by: Newsgroup User
    I have a form that allows users to select multiple items from a list.

    form.hobbies = 1,5,3,6,8,2 (from a table pullup)
    I want to be able to search a table of users where
    each user has a column of "hobbies" also a list.

    How can my select statement parse the table of
    users and compare and select those users
    who have at least one hobby in their record
    that is in the selected form.hobbies?

    I am a bit braindead on this one :)
    Tx in advance.... I have the CF end
    worked out, just need the SQL portion of it.


    --
    Tami
    aka DixieGal

    **************************
    So it is that the gods to dno give all men gifts of grace - neither good
    looks not intelligence nor eloquence...
    --Homer, The Odyssey
    **************************





    Dan Bracuk Guest

  5. #4

    Default Re: Searching a column containing a list against a form list

    yea, I know. I was just being lazy <wink>. The more I
    chew on it, the more of a no-brainer it is....

    On a similar note that may be helpful to others,
    I did find CF_LIST_COMPARE
    which is a custom tag that does compare 2 lists. And
    it is very nice... returns a list of all items in first list but
    not in second, a list of all items in second but not first,
    and a list of all items in both lists. Found it on MM site :)

    THanks all... I will quit being lazy for now, and do it right
    <wink>
    Tami

    --
    Tami
    aka DixieGal

    **************************
    So it is that the gods to dno give all men gifts of grace - neither good
    looks not intelligence nor eloquence...
    --Homer, The Odyssey
    **************************
    "Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
    news:dj421n$7q5$1@forums.macromedia.com...
    | As mxstu said, your data structure makes it easy to load records, but very
    | difficult to use them for anything. But, it you gotta go with what ya
    got,
    | this will work.
    |
    | <cfsetting requestTimeout="a very large number">
    | <cfloop list="form.hobbies" index = "hobby">
    | <cfquery>
    | select stuff from tableofusers
    | where hobbies like '%#hobby#%'
    | </cfquery>
    | something to store results so far.
    | </cfloop>
    |
    |
    | Originally posted by: Newsgroup User
    | I have a form that allows users to select multiple items from a list.
    |
    | form.hobbies = 1,5,3,6,8,2 (from a table pullup)
    | I want to be able to search a table of users where
    | each user has a column of "hobbies" also a list.
    |
    | How can my select statement parse the table of
    | users and compare and select those users
    | who have at least one hobby in their record
    | that is in the selected form.hobbies?
    |
    | I am a bit braindead on this one :)
    | Tx in advance.... I have the CF end
    | worked out, just need the SQL portion of it.
    |
    |
    | --
    | Tami
    | aka DixieGal
    |
    | **************************
    | So it is that the gods to dno give all men gifts of grace - neither good
    | looks not intelligence nor eloquence...
    | --Homer, The Odyssey
    | **************************
    |
    |
    |
    |
    |

    DixieGal 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