acctman Posted April 29, 2009 Share Posted April 29, 2009 can someone assist me with a query example that checks to see if a string exist. $String = "Mike"; mysql query to check to see if $String exist in table Members, field Users... Quote Link to comment https://forums.phpfreaks.com/topic/156156-solved-query-to-check-to-see-if-string-exist/ Share on other sites More sharing options...
Mchl Posted April 29, 2009 Share Posted April 29, 2009 SELECT Users FROM Members WHERE Users LIKE '%Mike%' If you get rows, string exists, if no...then it diesn't This one will even tell you Yes or No SELECT IF(COUNT(*) > 0,"Yes","No") AS stringExists FROM Members WHERE Users LIKE "%Mike%" LIMIT 1; Quote Link to comment https://forums.phpfreaks.com/topic/156156-solved-query-to-check-to-see-if-string-exist/#findComment-822031 Share on other sites More sharing options...
rhodesa Posted April 29, 2009 Share Posted April 29, 2009 to extend on Mchl...this will return records like: Mike Jones John Mikel Fred Amiken Quote Link to comment https://forums.phpfreaks.com/topic/156156-solved-query-to-check-to-see-if-string-exist/#findComment-822043 Share on other sites More sharing options...
Mchl Posted April 29, 2009 Share Posted April 29, 2009 So? They all contain string "Mike" (well maybe apart from Amiken... not sure if LIKE can be case sensitive?) [edit] Sure it can! SELECT Users FROM Members WHERE Users LIKE BINARY '%Mike%' Quote Link to comment https://forums.phpfreaks.com/topic/156156-solved-query-to-check-to-see-if-string-exist/#findComment-822064 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.