...

View Full Version : LIKE and AND?



JoeStork
05-25-2011, 01:30 PM
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

abduraooft
05-25-2011, 01:37 PM
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?

JoeStork
05-25-2011, 01:49 PM
$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))

JoeStork
05-25-2011, 03:24 PM
Please help!

Inigoesdr
05-25-2011, 06:51 PM
You're missing the if() condition in your code. Based on your original example the final query should look like:

$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"?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum