I have the following code which has two fields that are queried.
How can I do LIKE
with 3-5 fields?
Code:
mysql_que开发者_如何学Pythonry("SELECT * FROM practice_exams where
person_id = '$pid' and message_exam LIKE
'%$q%' OR message_note LIKE '%$q%'");
I assume you mean searching instead of querying. Adding more fields becomes easier if you structure your statement nicer:
mysql_query("
SELECT * FROM practice_exams
WHERE person_id = '$pid'
AND (
message_exam LIKE '%$q%'
OR message_note LIKE '%$q%'
OR other_note LIKE '%$q%'
OR other_things LIKE '%$q%'
)
");
I've added some parens there, as I assume that's what your query actually should do.
Note that a lot of LIKE
statements do not benefit the query speed.
精彩评论