dqg2269 2015-03-06 01: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 13: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

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

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办