简体   繁体   English

带有OR语句的MYSQL查询中的数组

[英]array in MYSQL query with OR statements

I have a where clause that is in an array, I am having a problem where i need service.active = 1 to also possible match 2,3 or 4. 我有一个数组中的where子句,我有一个问题,我需要service.active = 1也可能匹配2,3或4。

I am not sure how to do this in an array. 我不知道如何在数组中执行此操作。 So i wanted: 所以我想:

service.active = 1 OR service.active = 2 OR service.active 3 OR service.active = 4 service.active = 1 OR service.active = 2 OR service.active 3 OR service.active = 4

at the moment i can only get it to work by 'service.active' => 1, 目前我只能通过'service.active'=> 1让它工作,

#Get the data
$services = get_services(array(
    'service.id' => $service_id, //Service we are trying to get
    'service.active' => 1, //Active services only
    'service.owner_id' => $userid, //Just to be sure another user isn't   trying to get a service that isn't theirs
));

Answered by Daryl B in this comment : Daryl B在此评论中回答:

Have an SQL statement like this? 有这样的SQL语句吗? SELECT * FROM service WHERE service.active IN (1,2,3,4); SELECT * FROM service WHERE service.active IN(1,2,3,4); Dont use OR it can cause problems and its a bit slow. 不要使用OR它可能会导致问题而且有点慢。 I dont know if you are using a RAW SQL query or a PDO prepared statement to help further. 我不知道您是否使用RAW SQL查询或PDO预处理语句来进一步帮助。 But you can implode the array to get the list 但是你可以内爆数组来获取列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM