Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > MySQL Query

MySQL Query
Thread Tools
Junior Member
Join Date: May 2003
Status: Offline
Reply With Quote
Apr 28, 2004, 07:44 PM
 
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
www.jmarus.com - kicks by JM
     
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Apr 28, 2004, 08:05 PM
 
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');
     
jon31  (op)
Junior Member
Join Date: May 2003
Status: Offline
Reply With Quote
Apr 28, 2004, 08:10 PM
 
I was not familiar with the brackets use like that. Can you explain that a little? Or point me to someplace that does?

Thanks!
www.jmarus.com - kicks by JM
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Apr 28, 2004, 08:12 PM
 
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
     
jon31  (op)
Junior Member
Join Date: May 2003
Status: Offline
Reply With Quote
Apr 28, 2004, 08:20 PM
 
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
www.jmarus.com - kicks by JM
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Apr 28, 2004, 10:24 PM
 
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
Reply With Quote
Apr 28, 2004, 10:25 PM
 
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
     
jon31  (op)
Junior Member
Join Date: May 2003
Status: Offline
Reply With Quote
Apr 28, 2004, 10:32 PM
 
Thanks guys, worked great! Even met my deadline as well.
www.jmarus.com - kicks by JM
     
   
Thread Tools
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -5. The time now is 06:28 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2