我在select语句上还很新,所以有人可以协助我完成我要完成的PHP查询。

MYSQL表中有5列(Partner_Name,Partner_Name2,Partner_Name3,Partner_Name4,Partner_Name5)

我当前的PHP语句如下所示。

$query = mysqli_query( $connection, "SELECT * FROM tblclients  WHERE tblclients.partner_name =  'Store_1' AND tblclients.package =  'standard' AND tblclients.category = 'all' LIMIT 0, 9");


我的目标是要有这样的东西...

$query = mysqli_query( $connection, "SELECT * FROM tblclients WHERE tblclients.partner_name =  'Store_1' OR tblclients.partner_name_2 =  'Store_1' OR tblclients.partner_name_3 =  'Store_1' OR tblclients.partner_name_4 =  'Store_1' OR tblclients.partner_name_5 =  'Store_1' AND tblclients.package =  'standard' AND tblclients.category = 'all'  0, 9");


它似乎没有以我期望的方式返回结果。我做错了吗?

最佳答案

顺便说一句,您忘记在第二个查询上添加LIMIT。


  $ query = mysqli_query($ connection,“ SELECT * FROM tblclients,其中tblclients.package ='standard'AND tblclients.category ='all'AND(tblclients.partner_name ='Store_1'或tblclients.partner_name_2 ='Store_1'或tblclients.partner_name_3 ='Store_1'OR tblclients.partner_name_4 ='Store_1'OR tblclients.partner_name_5 ='Store_1')LIMIT 0,9“);


而且,如果您有时间,也许可以对表进行优化,以便查询更好,更易于阅读。

关于php - Mysql Select语句使用OR,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36439180/

10-12 23:42