3 field search not working

Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #1

    Default 3 field search not working

    I have a 3 field search
    [url]http://www.websitemedia.net/demo/7665/without_fl/qualitymotorsdemo.cfm[/url] The 3
    fields work great individually. But i am having a lot of trouble searching if
    2 fields are picked or 3 fields are picked. Below is my code. I have tried
    adding a cfelse but it still fails to work. Am i mising something? Please
    look the code over and let me if i am missing something very obvious. Thanks
    in advancd and greatly appreciated, Braulio.

    SELECT stock, make, price, description, image, qualitymotorsdemo.page
    FROM qualitymotorsdemo
    <cfif trim(#FORM.select#) neq "all">
    WHERE make = '#FORM.select#'
    </cfif>
    <cfif trim(#FORM.year#) neq "all">
    WHERE year = '#FORM.year#'
    </cfif>
    <cfif trim(#FORM.model#) neq "all">
    WHERE model = '#FORM.model#'
    </cfif>

    braulio! Guest

  2. Similar Questions and Discussions

    1. Eliminating null field on search
      I have a Select statement that is has lines in it like: WHERE memberstatus = 'Renewal' and email is not null I am still getting results that...
    2. Help with making a Search field
      I would realy appreciate some help. I need to create a search field in my web site and dont know how to create it and link it to seach the site....
    3. Creating a Search Field
      Hey peeps, can ne1 help me ... i'm trying to create a search facility .. i want it to work just how any other search facility would work .. user...
    4. I need a search field badly
      I would like to create a search field so that visitors can search for a page containing a particular word or item. What is an easy way to do this....
    5. concat fields then search the new field
      how would I concatenate several fields from a record set then search the new field for individual keywords ? something like: Dim theArray ...
  3. #2

    Default Re: 3 field search not working

    SELECT stock, make, price, description, image, qualitymotorsdemo.page
    FROM qualitymotorsdemo
    WHERE 1 = 1
    <cfif trim(#FORM.select#) neq "all">
    AND make = '#FORM.select#'
    </cfif>
    <cfif trim(#FORM.year#) neq "all">
    AND year = '#FORM.year#'
    </cfif>
    <cfif trim(#FORM.model#) neq "all">
    AND model = '#FORM.model#'
    </cfif>

    the 1 = 1 is needed, so don't take it out.

    Kronin555 Guest

  4. #3

    Default Re: 3 field search not working

    OK great it worked. But what is the logic behind the "where 1 =1". I looked
    for a way to do this in my cf mx7 web appication consruction kit reference book
    but no dice. Thanks but please explain so that i can understand it. Braulio.

    braulio! Guest

  5. #4

    Default Re: 3 field search not working

    I have also been trying to make the drop down menu display the value selected
    but it always "All". I have looked at the select statement but have been
    unable to set it up to display the value selected by the visitor. Any input on
    this will be greatly appreciated, Braulio.

    braulio! Guest

  6. #5

    Default Re: 3 field search not working

    the logic behind the 1 = 1... ok.

    in order to simplify things, you need a dummy where test that always equals
    true (in the case where you're ANDing everything together), or always equals
    false (in the case where you're ORing everything together). That way in your if
    statements you can ignore the concern of whether the WHERE clause has been
    started or not.

    Here's 2 examples, one with the 1=1, and one without:

    SELECT * FROM foo
    WHERE
    testCol = 'test'

    SELECT * FROM foo
    WHERE 1 = 1
    AND testCol = 'test'

    they both match the same columns. you're essentially putting a dummy "true" in
    your AND list of checks. because it's "true", it doesn't have any impact on the
    results. The reason you put it in there is so when you wrap the "testCol =
    'test'" in a <cfif>, you have to wonder whether you need to put an AND at the
    front or not. with the dummy 1 = 1 in there, you know you always put an AND in
    the front of the clause, and it will always result in a valid query. Also, if
    you take out the "AND testCol = 'test'" in the second query, you get this:

    SELECT * FROM foo
    WHERE 1 = 1

    which returns the exact same information as this:

    SELECT * FROM foo

    it just simplifies tacking on more tests to the WHERE clause.

    Kronin555 Guest

  7. #6

    Default Re: 3 field search not working

    Thank you very much for teaching me how to fish. I appreciate it, Braulio.
    braulio! 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