我有以下代码,其中包含两个要查询的字段。
如何使用3-5个字段进行LIKE
?
代码:
mysql_query("SELECT * FROM practice_exams where
person_id = '$pid' and message_exam LIKE
'%$q%' OR message_note LIKE '%$q%'");
答案 0 :(得分:3)
我认为你的意思是搜索而不是查询。如果您更好地构建语句,则添加更多字段会变得更容易:
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%'
)
");
我在那里添加了一些parens,因为我认为这是你的查询实际应该做的。
请注意,许多LIKE
语句不会使查询速度受益。