dqg2269 2015-03-05 17:58
浏览 56
已采纳

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

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.

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

at the moment i can only get it to work by '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
));
  • 写回答

1条回答 默认 最新

  • dongshan9619 2016-09-09 05:57
    关注

    Answered by Daryl B in this comment:

    Have an SQL statement like this? SELECT * FROM service WHERE service.active IN (1,2,3,4); Dont use OR it can cause problems and its a bit slow. I dont know if you are using a RAW SQL query or a PDO prepared statement to help further. But you can implode the array to get the list

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部