SELECT - finding array elements in a astring
Date: 12/21/05
(MySQL Communtiy) Keywords: no keywords
I have a col, cats
, that contains data like "#Art, Music, & Books#Consumer Electronics#Cruises"
When I am selecting rows, I want to see if any elements in an array match a sub string in cats.
Sample array to match: UserCats = array('Cruises', 'Baby');
I guess what I want to do is convert cats
to an array and then find out if it intersects with UserCats
.
THX
Here is my current working query
SELECT
ad.userID,
ad.adID,
ad.adTitle,
ad.adBlurb,
ad.endDate,
ad.postingDate,
ad.paymentStatus,
loc.userAdID,
loc.streetAddress,
loc.city,
loc.zip,
loc.state,
u.vendorCompanyName,
u.phone
FROM fb_user AS u
INNER JOIN vendorAd AS ad ON u.userID = ad.userID
LEFT JOIN adLocation AS loc ON ad.userID = loc.userID AND ad.userAdID = loc.userAdID
WHERE ad.status = \"active\"
AND ad.paymentStatus =\"mickeymouse\"
AND ad.hideRecord =\"n\"
AND ad.endDate >= \"".$formattedToday."\"
AND (loc.zip IN($zips) OR loc.city IN($cities))
ORDER BY ad.endDate
Source: http://www.livejournal.com/community/mysql/79325.html