search MySQL field for any item from array

06-23-09, 01:36 PM
|
|
Newbie Coder
|
|
Join Date: Sep 2004
Location: Alexandria, Egypt.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
search MySQL field for any item from array
Now, I've MySQL field called `catgegory_ids`, if one row contains (1,5,23,45) . how can I make a search if any of these categories (1,5) are found ??
I thought of making the following:
But I feel it's stupid way !
|

06-23-09, 01:46 PM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
|
|

06-23-09, 03:19 PM
|
|
Newbie Coder
|
|
Join Date: Sep 2004
Location: Alexandria, Egypt.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Nico
|
now I add the value to `category_ids` and here're the results
Working.
Not working
Not working
|

06-26-09, 06:42 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
Perhaps you should spell "items" right...
And your first and second query are the same, only one works but the other doesn't?
|

06-27-09, 05:13 AM
|
|
Newbie Coder
|
|
Join Date: Sep 2004
Location: Alexandria, Egypt.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Jcbones
Perhaps you should spell "items" right...
And your first and second query are the same, only one works but the other doesn't?
|
BTW, the real table name is not items I just changed it here while writing the reply, so it's not a miss-spell !
and 2nd query which is not working , should be
|

06-28-09, 01:48 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
There is no reason those queries shouldn't work.
Have you put them into mysql console to see if it returns an error message?
|

06-29-09, 04:15 AM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
I think the reason it doesn't work is:
Quote:
Originally Posted by m_abdelfattah
if one row contains (1,5,23,45)
|
You're going to have to use regular expressions to have this work correctly. This isn't the best practice, though. You should use a third table to store the relations.
Anyway:
(Untested, but should work)
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting 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
|
|
|
|