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

时间:2015-03-06 01:58:22

标签: php mysql

我有一个数组中的where子句,我有一个问题,我需要service.active = 1也可能匹配2,3或4。

我不确定如何在数组中执行此操作。 所以我想:

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

目前我只能通过&service; active.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
));

1 个答案:

答案 0 :(得分:0)

Daryl B在this comment回答:

  

有这样的SQL语句吗? SELECT * FROM service WHERE service.active IN(1,2,3,4);不要使用OR它可能会导致问题而且有点慢。我不知道您是否使用RAW SQL查询或PDO预处理语句来进一步帮助。但你可以内爆数组来获取列表