tetuanrp Posted July 1, 2009 Share Posted July 1, 2009 I have a site with a ton of coupons. Each coupon is a row in the database, and has a deal_description for each coupon. Currently, if I want to search all of the deals, for a number of keywords, this is how I do it: Deal example (1 row of 10,000): "Basketball shoes 10 dollars off with coupon" Keywords I want to check against: "basketball, shoes" SQL QUERY ALL ROWS FOR LOOP FOR ARRAY OF KEYWORDS ('basketball','shoes') END LOOP END QUERY This causes a memory error with an array of over 2 items. Think the server can't handle 10,000 rows of coupons * an array w/ 5 items for example: 50,000 actions. Is there any way I can do a for loop like this?: FOR LOOP FOR ARRAY OF KEYWORDS ('basketball','shoes') SQL QUERY AGAINST DEAL_DESCTIPION FOR KEYWORD[$i] END QUERY END LOOP That would be much less intensive, although I don't think MYSQL has a Strpos function for me to check a string of text for a keyword. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/164422-strpos-as-mysql-query/ Share on other sites More sharing options...
fenway Posted July 2, 2009 Share Posted July 2, 2009 Assuming you actually store your keywords in a comma-separated list, FIND_IN_SET() will work. Quote Link to comment https://forums.phpfreaks.com/topic/164422-strpos-as-mysql-query/#findComment-867496 Share on other sites More sharing options...
tetuanrp Posted July 2, 2009 Author Share Posted July 2, 2009 Hmm, didn't know about that one. Not sure if that would work as I have a long description, not really comma seperated: ie. Haystack is "This is my long string about colors including blue, green, red and yellow" I wanna search this string using MYSQL for "green". Using php I'd do a strpos, but with MYSQL don't think there's a function for that. Quote Link to comment https://forums.phpfreaks.com/topic/164422-strpos-as-mysql-query/#findComment-867569 Share on other sites More sharing options...
tetuanrp Posted July 2, 2009 Author Share Posted July 2, 2009 Ahh, think I found my answer. The LIKE statement which I've never really used: SELECT * FROM mycoupons WHERE deal_description LIKE '%my keyword%'; Sometimes it just takes a few Google searches Thx Quote Link to comment https://forums.phpfreaks.com/topic/164422-strpos-as-mysql-query/#findComment-867572 Share on other sites More sharing options...
fenway Posted July 2, 2009 Share Posted July 2, 2009 Careful with substring matches... you're not matching whole words. Quote Link to comment https://forums.phpfreaks.com/topic/164422-strpos-as-mysql-query/#findComment-867590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.