MySQL query query

This is a discussion on "MySQL query query" within the Databases section. This forum, and the thread "MySQL query query are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Apr 12th, 2007, 10:21
Reputable Member
Join Date: Feb 2007
Location: UK
Posts: 190
Thanks: 0
Thanked 5 Times in 5 Posts
MySQL query query

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Apr 12th, 2007, 12:15
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: MySQL query query

Have you tried something like this?

Code: Select all
$query = "SELECT * FROM accessories WHERE (category = '$category') AND (code LIKE '%$search%' OR name LIKE '%$search%' OR description LIKE '%$search%')";
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Apr 12th, 2007, 12:40
Reputable Member
Join Date: Feb 2007
Location: UK
Posts: 190
Thanks: 0
Thanked 5 Times in 5 Posts
Re: MySQL query query

Gah!

Brackets. Doh

Cheers karinne
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Apr 12th, 2007, 12:45
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: MySQL query query

It worked? Ah .... cool!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
mysql multiple

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Mysql Query not working nate2099 Databases 13 Jan 3rd, 2008 02:28
MYSQL/PHP Query question andrewlondon Databases 1 Sep 19th, 2007 11:26
MYSQL PHP query class jhappeal Databases 1 Aug 17th, 2007 01:52
Returning a value from a MYSQL Query? Kimochi PHP Forum 7 Feb 28th, 2007 20:09
mysql query in a function Redempt1on PHP Forum 6 May 19th, 2006 01:25


All times are GMT. The time now is 22:20.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

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