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 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败