Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: LIKE and AND?

  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    LIKE and AND?

    Hi,

    I am after some help...

    I have a simple PHP search engine I have construct with 2 field, one a textarea called "search" and another a drop down menu called "type".

    I want to search a MYSQL database for the "search" entered by the user but it must only search for that "type", for example.

    Search = Bosch
    Type = Drills

    I want it to only search fields in "drills" for the keyword/s "Bosch". I have constructed the form/s and results page however, all works fine when I search for Bosch in drills however when I search for example Makita in drills in still shows the Bosch results...

    Could anyone provide the SELECT part that I need to use?

    Many thanks,

    Joe

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    all works fine when I search for Bosch in drills however when I search for example Makita in drills in still shows the Bosch results...

    Could anyone provide the SELECT part that I need to use?
    Could you please post what you've right now?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $construct .="search LIKE '%$search_each_%' AND type='"$type"'"

    else 
    $construct .="AND search LIKE '%$search_each%'"; } 

    $construct ="SELECT * FROM tooldata WHERE $construct AND type='"$type"'"

    $run mysql_query($construct); $foundnum mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for $search."

    else { echo 
    "$foundnum results found !
    "
    ; while($runrows mysql_fetch_assoc($run)) 
    Last edited by Inigoesdr; 05-25-2011 at 05:47 PM.

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please help!

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You're missing the if() condition in your code. Based on your original example the final query should look like:
    PHP Code:
    $construct "SELECT * FROM `tooldata` WHERE `search` LIKE '%Bosch%' AND `type`= 'Drills'"
    So, just figure out in your logic what is being generated and how it needs to change. Is your brand/product field actually named "search"?


  •  

    Posting Permissions

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