Click to See Complete Forum and Search --> : MySQL query query


dangergeek
04-12-2007, 07:12 AM
Hello

I'm creating a search engine for my site and i want to use the following query to search the database:

$query = "SELECT * FROM accessories WHERE category = '$category' AND code LIKE '%$search%' OR name LIKE '%$search%' OR description LIKE '%$search%'";

This doesnt seem to work!

I can get his to work:

$query = "SELECT * FROM accessories WHERE category = '$category'";

and I can get this to work:

$query = "SELECT * FROM accessories WHERE code LIKE '%$search%' OR name LIKE '%$search%' OR description LIKE '%$search%'";

I just cant combine the two queries to make the larger first one. The AND seems to break the query. Is this possible?

Only way I can think of getting round this is making another table and doing a join but that seems excessive. Is this a limitation of MySQL or can some one point me in the right direction.

Thanks