-2
我有以下代码,其中有两个字段被查询。如何查询数据库中的多个字段?
我该怎么做LIKE
3-5字段?
代码:
mysql_query("SELECT * FROM practice_exams where
person_id = '$pid' and message_exam LIKE
'%$q%' OR message_note LIKE '%$q%'");
我有以下代码,其中有两个字段被查询。如何查询数据库中的多个字段?
我该怎么做LIKE
3-5字段?
代码:
mysql_query("SELECT * FROM practice_exams where
person_id = '$pid' and message_exam LIKE
'%$q%' OR message_note LIKE '%$q%'");
我假设你的意思是搜索,而不是查询。添加更多领域成为你组织你的说法更好更轻松:
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%'
)
");
我已经添加了一些括号那里,因为我认为这是你的查询实际上应该做的事情。
请注意,很多LIKE
语句不利于查询速度。
你指的是什么字段?你的意思是限制返回的行数限制SELECTED的字段(不使用*之类的通配符)? – gruntled 2011-05-08 23:26:47
“查询字段”是什么意思?他们在“哪里”条款?如果是这样,你已经参考3(虽然应该可能有括号内) – 2011-05-08 23:27:04
你可以重述这个问题,这样才有意义吗? – 2011-05-08 23:27:17