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
Many SQL systems let you push it as a character value. CHAR(10) = Linefeed. So, occasionally, instead of working out all the escape coding, you can push single quotes, double quotes and other things into a sql string this way, without too many other coding issues.
-Just a hint.
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.