I know how to perform an SQL LIKE % query for a single value like so:
SELECT * FROM users WHERE name LIKE %tom%;
but how do I do this if th
i just took the code of 472084.
$sql = array('0'); // Stop errors when $words is empty
foreach($words as $word){
$sql[] = 'name LIKE %'.$word.'%'
}
$sql = 'SELECT * FROM users WHERE '.implode(" OR ", $sql);
For my self, i had to modify it because it's returned me an error SQL. I Post it for people who gonna read the thread.
foreach($words as $word){
$sql[] = 'name LIKE \'%'.$word.'%\'';
}
$sql = 'SELECT * FROM users WHERE '.implode(" OR ", $sql);
The difference between them is about quote, my mysql DB said there is a problem ! so i had to escape quote from $sql[] = 'name LIKE %'.$word.'%'
and now it's work perfectly.