 |
 |
MySQL Query
|
 |
|
 |
|
Junior Member
Join Date: May 2003
Status:
Offline
|
|
Hey guys,
I'm trying to search a select few table rows in my MySQL table. I want to search any item that's in the category Retail, Nightlife or Restaurant, then, with those items, I want to look for any that match the search query.
Here is my current mysql query "SELECT * FROM GPBSD_Members WHERE b_name LIKE '%$query%' AND logo_loaded = '' OR content LIKE '%$query%' AND logo_loaded = ''"
That looks for any b_name that matches $query. But, I only want to check the retail, nightlife and restuarant items, which have the b_category of Retail, Nightlife or Restaurant.
Any ideas? Did this make any sense?
Thanks!
Jon Marus
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 2003
Status:
Offline
|
|
have you tried something like this:
Code:
SELECT * FROM GPBSD_Members WHERE ((b_name LIKE '%$query%' OR content LIKE '%$query%') AND logo_loaded = '') AND (b_category = 'Retail' OR b_category = 'Nightlife' OR b_category = 'Restaurant');
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2003
Status:
Offline
|
|
I was not familiar with the brackets use like that. Can you explain that a little? Or point me to someplace that does?
Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Some thing like this?
Code:
SELECT * FROM GPBSD_Members
WHERE
(
b_name LIKE '%$query%'
AND logo_loaded = ''
)
OR
(
content LIKE '%$query%'
AND logo_loaded = ''
)
AND b_category IN ('Retail', 'Restaurant', 'Nightlife')
)
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2003
Status:
Offline
|
|
Hmm.. the first one worked, but the second one looks interesting too. I didn't know how to do either, so that's a plus on my half.
Now I just have to figure out how to do the opposite, ei. search all the fields that AREN'T retail, restaurant or nightlife
I'll keep workin at it.
Jon
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status:
Offline
|
|
Originally posted by jon31:
Hmm.. the first one worked, but the second one looks interesting too. I didn't know how to do either, so that's a plus on my half.
Now I just have to figure out how to do the opposite, ei. search all the fields that AREN'T retail, restaurant or nightlife
I'll keep workin at it.
Jon
Arkham's code is probably a bit more graceful IMHO and makes better use of the string search functions - the comma-delimited set is a very handy search syntax (see also FIND_IN_SET in the MySQL documentation)
|
|
Computer thez nohhh...
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status:
Offline
|
|
Originally posted by jon31:
Now I just have to figure out how to do the opposite, ei. search all the fields that AREN'T retail, restaurant or nightlife
Code:
AND b_category NOT IN ('Retail', 'Restaurant', 'Nightlife')
That will do what you ask.
|
|
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2003
Status:
Offline
|
|
Thanks guys, worked great! Even met my deadline as well.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|