dongshiliao7990 2016-02-19 12:15
浏览 131

WHERE或使用PHP-MySQLi-Database-Class进行查询

I am using MysqlDb Class in my Project.

$fromquery = $jdb->where("ac_ag_Id",1)->orWhere("ac_ag_Id",2)->orWhere("ac_ag_Id",4)->orWhere("ac_ag_Id",17)->where("c_Id",$cc_Id)->get("tbl_accounts")

This is my current query and the result is

SELECT  * FROM tbl_accounts WHERE  ac_ag_Id = '1'  OR ac_ag_Id = '2'  OR ac_ag_Id = '4'  OR ac_ag_Id = '17'  AND c_Id = '2'

Here, c_Id must be 2, but I am getting result of c_Id of 1 also. So I added a bracket which looks like this and I get the currect result

SELECT  * FROM tbl_accounts WHERE  (ac_ag_Id = '1'  OR ac_ag_Id = '2'  OR ac_ag_Id = '4'  OR ac_ag_Id = '17')  AND c_Id = '2' 

How to get this result form that class like adding function andWhere or something?

  • 写回答

2条回答 默认 最新

  • douao3063 2016-02-19 12:21
    关注

    You should use IN clause instead of write multiple OR operator

    SELECT  * FROM tbl_accounts WHERE  ac_ag_Id IN(1,2,4,17);
    

    using IN clause you get all record which ac_ag_Id in (1,2,4,17).

    for more about IN clause link. above query run on mysql. i am not php developer

    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)