繁体   English   中英

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

[英]array in MYSQL query with OR statements

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

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

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

目前我只能通过'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
));

Daryl B在此评论中回答:

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

暂无
暂无

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

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