Comma seprated search in mysql query
Posted
by
Ravi Kotwani
on Stack Overflow
See other posts from Stack Overflow
or by Ravi Kotwani
Published on 2012-04-07T10:12:17Z
Indexed on
2012/04/07
11:28 UTC
Read the original article
Hit count: 699
I have search mechanism in my site. For that I have written a large conditional query.
$sql = "select * from users where
keyword like '%".$_POST['search']."%'
OR name like '%".$_POST['search']."%'";
Now, I suppose I have following data on the site:
ID Name Keyword
1 Sanjay sanjay, surani
2 Ankit ankit, shah
3 Ravi ravi, kotwani
Now, I need the result such that when user writes "sanjay, shah" ($_POST['search'] = 'sanjay, shah')
then records 1 and 2 should be displayed.
Can I achive this in single mysql query?
© Stack Overflow or respective owner