$result=mysql_query("SELECT* FROM name WHERE name like 'name1' OR name like 'name2'...");
I have more than 20 words add into SELECT FROM WHERE like. Is there anyway to short the code?
Such as: $result=mysql_query("SELECT* FROM table WHERE name like (name1, name2, name3, name4…) );
Of course this code is wrong, just an analogy.
$whereLike = array( 'name1', 'name2', 'name3', 'name4' );
$sql = 'SELECT * FROM table WHERE col like ';
$sql .= implode( ' OR ', $whereLike );
$result = mysql_query( $sql );
i say no, no, no to the previous suggestions
since you are ~not~ using a wildcard character, you are getting equality conditions, and you don’t need LIKE
use this –
WHERE name IN ('name1','name2','name3'...)
you probably would want to run a loop before running the query.
that is a good one… i love learning new SQL statements.
Hello, r937, you’re right. I don’t know WHERE…IN before, but now you teached me.Thank you.
Also thanks for acid24ro and Shaydez.