filtering a QUERY with WHERE and a list

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

  1. #1

    Default filtering a QUERY with WHERE and a list

    this sounds like it should be easy but i'm stuck and i have ran out of ideas.
    okay this is what i need done.
    in my DB i have a table named links with fileds: link_id , link_name ,
    link_url , catagories .
    the catagories field has a list of matching catagories. what i want to do now
    is when a user clicks on a catagory from a list on a page. i want the query to
    look at the list in the catagories field and see if the clicked catagory is
    present and only show those results.

    query simple example: does not work

    <CFQUERY NAME="Links2Get" DATASOURCE="myDB">
    SELECT *
    FROM links
    WHERE catagories LIKE #clickedCatagory#
    </CFQUERY>

    query w/ output exaple : this works but i want to do it in the query so i
    could have the right recordCount

    <CFQUERY NAME="Links2Get" DATASOURCE="myDB">
    SELECT *
    FROM links
    </CFQUERY>

    <cfif Links2Get.catagories contains '#clickedCatagory#'>
    <cfoutput>#link_name# : #link_url#<cfoutput>
    </cfif>

    gabberartist Guest

  2. Similar Questions and Discussions

    1. List to Query
      Hi, Can someone please tell me the best way to convert a list into a query? Thanks, Steve
    2. query to list
      i need to convert a query column values to list , is there any way to do that, pls.help thanks in advance.
    3. Filtering query results
      Hi, How do I filter result output data based on WHERE clauses in a query like below. This query should output based upon #FORM.city# OR #URL.city#...
    4. Convert a query to a list, or find an item in a query
      Hi All, I am using CFPOP to retrieve mail from a server, then delete each message after I retrieve it. What I want to do is to check that I don;t...
    5. List all query names
      I'm on a server that does not allow me to look at the normal debuging information. Does anyone know how to loop over all the queries and dump the...
  3. #2

    Default Re: filtering a QUERY with WHERE and a list

    First off, i think you're going to want to put quotes around the
    #clickedCategories# variable. The SQL code would look like this..

    <CFQUERY NAME="Links2Get" DATASOURCE="myDB">
    SELECT *
    FROM links
    WHERE catagories LIKE '#clickedCatagory#'
    </CFQUERY>

    I know if your using an Access DB, you will get an error if you do not use
    quotes on a field that is set to any type except INTEGER.

    Hope that helps!

    Explorer5 Guest

  4. #3

    Default Re: filtering a QUERY with WHERE and a list

    thanks but that didn't work .

    i need 2 match #clickedCatagory# to a list in the catagories filed in my DB.


    gabberartist Guest

  5. #4

    Default Re: filtering a QUERY with WHERE and a list

    What is the error code you are getting?
    Explorer5 Guest

  6. #5

    Default Re: filtering a QUERY with WHERE and a list

    i get no results
    gabberartist Guest

  7. #6

    Default Re: filtering a QUERY with WHERE and a list

    I am not sure whether I got the right understanding of your question but
    normally when you use LIKE to do the pattern match then you should use it as
    below:

    <CFQUERY NAME="Links2Get" DATASOURCE="myDB">
    SELECT *
    FROM links
    WHERE catagories LIKE '%#clickedCatagory#%'
    </CFQUERY>

    There are other means too, where you can do the SQL query as a click event and
    select the categories from the table based on the selected category.

    surenr Guest

  8. #7

    Default Re: filtering a QUERY with WHERE and a list

    In that case, the code is working - it sounds as though the data that is going
    through is not the same as what is in the database. Have you double/triple
    checked that the data that is being passed is the exact same data that should
    be compared against the database (i know it sounds bad.. But i cant tell you
    how many times i have double checked, then triple checked, and then the fourth
    time, i found i made a mistake).

    Explorer5 Guest

  9. #8

    Default Re: filtering a QUERY with WHERE and a list

    thank you very much surenr. i knew it had to be someThing very easy.
    gabberartist Guest

  10. #9

    Default Re: filtering a QUERY with WHERE and a list

    hey I am genious,makes me proud
    surenr 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