Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2011, 12:30 PM   PM User | #1
JoeStork
New to the CF scene

 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
JoeStork is an unknown quantity at this point
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
JoeStork is offline   Reply With Quote
Old 05-25-2011, 12:37 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-25-2011, 12:49 PM   PM User | #3
JoeStork
New to the CF scene

 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
JoeStork is an unknown quantity at this point
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..
JoeStork is offline   Reply With Quote
Old 05-25-2011, 02:24 PM   PM User | #4
JoeStork
New to the CF scene

 
Join Date: May 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
JoeStork is an unknown quantity at this point
Please help!
JoeStork is offline   Reply With Quote
Old 05-25-2011, 05:51 PM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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"?
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:08 PM.


Advertisement
Log in to turn off these ads.