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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?