Php 多个和/或运算符在mysql查询中未按预期工作

Php 多个和/或运算符在mysql查询中未按预期工作,php,mysql,Php,Mysql,我正在尝试查询我的items表并基于搜索查询获取项目,但我想从这些结果中排除状态为2或0的项目,1表示可供投标的项目 到目前为止,我的问题是 SELECT a.item_id,a.auction_id as item_auction_id,a.item_code,a.name as item_name,a.description as item_desc,a.full_description as item_full_desc,a.image as item_image,a.donor as i

我正在尝试查询我的items表并基于搜索查询获取项目,但我想从这些结果中排除状态为2或0的项目,1表示可供投标的项目

到目前为止,我的问题是

SELECT a.item_id,a.auction_id as item_auction_id,a.item_code,a.name as item_name,a.description as item_desc,a.full_description as item_full_desc,a.image as item_image,a.donor as item_donor,a.cost as item_cost,a.value as item_value,a.reserve as item_reserve,a.bid_increment as item_bid_increment,a.buy_price as item_buy_price,a.status as item_status,a.published as item_published,a.paid as item_paid,a.pay_type as item_pay_type, a.transaction_id as item_transaction_id,a.is_raffle as item_is_raffle,a.raffle_price as item_raffle_price, a.raffle_qty as item_raffle_qty,a.live_auction as item_live_auction,a.active as item_active,a.refunded as item_refunded, MAX(b.bid_amt) as item_high_bid,b.user_id as item_high_bid_user_id,b.bid_time as item_high_bid_time, b.bid_id as item_high_bid_id,SUM(c.raffle_ticket_qty) as item_tickets_purchased, '0000,0000' as item_bid_history, 0 as watching
        FROM text2bid_items as a
        LEFT JOIN (SELECT user_id, item_id, MAX(bid_amt) as bid_amt, bid_time, bid_id FROM text2bid_bids GROUP BY bid_id) as b
        ON a.item_id = b.item_id
        LEFT JOIN text2bid_raffle_purchases as c
        ON a.item_id = c.item_id
        WHERE a.name LIKE '%$params[2]%'
        OR a.description LIKE '%$params[2]%'
        OR a.full_description LIKE '%$params[2]%' 
        AND a.status = 1
        GROUP BY a.item_id
但是状态为2或0的项目仍然显示在我的结果中。我确信这与
的使用都有关系,但我不确定如何通过谷歌搜索找到解决方法,我尝试了
()
的不同组合,看看是否可以获得不同的优先级,但这可能不是解决方案


结果应该是
名称、描述或完整描述
与搜索查询类似的任何项目,但我想排除那些不具有
状态
等于1的项目

查询中的逻辑运算符混合。因此,最好将它们放在括号中,以便使查询逻辑保持得体。 我已经相应地更新了查询,请检查

SELECT a.item_id,a.auction_id as item_auction_id,a.item_code,a.name as item_name,a.description as item_desc,a.full_description as item_full_desc,a.image as item_image,a.donor as item_donor,a.cost as item_cost,a.value as item_value,a.reserve as item_reserve,a.bid_increment as item_bid_increment,a.buy_price as item_buy_price,a.status as item_status,a.published as item_published,a.paid as item_paid,a.pay_type as item_pay_type, a.transaction_id as item_transaction_id,a.is_raffle as item_is_raffle,a.raffle_price as item_raffle_price, a.raffle_qty as item_raffle_qty,a.live_auction as item_live_auction,a.active as item_active,a.refunded as item_refunded, MAX(b.bid_amt) as item_high_bid,b.user_id as item_high_bid_user_id,b.bid_time as item_high_bid_time, b.bid_id as item_high_bid_id,SUM(c.raffle_ticket_qty) as item_tickets_purchased, '0000,0000' as item_bid_history, 0 as watching
            FROM text2bid_items as a
            LEFT JOIN (SELECT user_id, item_id, MAX(bid_amt) as bid_amt, bid_time, bid_id FROM text2bid_bids GROUP BY bid_id) as b
            ON a.item_id = b.item_id
            LEFT JOIN text2bid_raffle_purchases as c
            ON a.item_id = c.item_id
            WHERE (a.name LIKE '%$params[2]%'
            OR a.description LIKE '%$params[2]%'
            OR a.full_description LIKE '%$params[2]%') 
            AND a.status = 1
            GROUP BY a.item_id

您正在混合
以及
而不使用任何
()
来强制执行解析顺序。您需要了解。在条件中使用括号;即使您知道运算符的进位,也会使其更易于阅读,并且您的意图也很清楚。。。下一个读取代码的人不知道之前的人是依赖于运算符优先级,还是。。。不是。我想我试过这个,可能是打字错误,这个很有效,谢谢!酷。如果这对您有效,请将答案标记为正确,以帮助社区。