开发者

How to query multiple fields in the db?

开发者 https://www.devze.com 2023-03-03 15:39 出处:网络
I have the following code which has two fields that are queried. How can I do LIKE with 3-5 fields? Code:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消