douao2019 2016-11-30 22:14
浏览 75
已采纳

Codeigniter Active Record问题(在哪里和多个'AND''OR')

could somebody tell me how to generate the following query with codeigniter active record?

SELECT * FROM `tbl_admins` WHERE (`email`='ci@php.net' OR `uname`='user') AND `upass`='SecretePass';

not writing the query, I mean passing different values through arrays... or CI Active Record

thank you

  • 写回答

3条回答 默认 最新

  • doujiao9426 2016-11-30 22:26
    关注

    I believe you can do this in a few ways. First, I am assuming you are passing in an array to the model function and that array is $filters.

    Option One

    $this->db->select('*');
    $this->db->from('tbl_admins');
    $this->db->where('email', $filters["email"]);
    $this->db->or_where('uname', $filters["email"]); 
    $this->db->where('upass', $filters["password"]);
    

    Option Two

    $this->db->select('*');
    $this->db->from('tbl_admins');
    $this->db->where("(email = '$filters["email"]' OR uname = '$filters["email"]') AND upass = '$filters["password"]'");
    

    I did not test, so you may need to adjust the variables in option two's where a bit. But that is fairly close to what you want.

    Here is another example of a similar Stack Overflow question.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决