Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何查询数据库中的多个字段?_Php_Mysql - Fatal编程技术网

Php 如何查询数据库中的多个字段?

Php 如何查询数据库中的多个字段?,php,mysql,Php,Mysql,我有下面的代码,其中有两个字段被查询 如何使用3-5个字段执行LIKE 代码: mysql_query("SELECT * FROM practice_exams where person_id = '$pid' and message_exam LIKE '%$q%' OR message_note LIKE '%$q%'"); 我想你的意思是搜索而不是查询。如果语句结构更好,则添加更多字段会更容易: mysql_query(" SELECT * FROM practic

我有下面的代码,其中有两个字段被查询

如何使用3-5个字段执行
LIKE

代码:

 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%'
           )
");
我在这里添加了一些参数,因为我认为这是您的查询实际上应该做的


请注意,许多类似于的语句对查询速度没有好处。

您所指的字段是什么?您的意思是限制为限制所选字段而返回的行数(不使用类似*的通配符)?“查询字段”是什么意思?它们是否在
where
子句中?如果是这样的话,你已经参考了第3条(虽然可能在那里应该有括号),你能重新措辞这个问题,使它有意义吗?