【问题标题】:How to search data using multiple where Codeigniter如何使用多个 where Codeigniter 搜索数据
【发布时间】:2018-02-15 09:12:49
【问题描述】:

当我想使用 Codeigniter 从我的数据库中搜索一些数据时,我遇到了一些问题。我想选择级别为 0 和 3 且状态为 1 的数据

    tb_user_data :  
         ----------------------------------
        | username | name | level | status |
         ----------------------------------
        | abb      | ab   | 0     | 1      |
        | abc      | aa   | 1     | 1      |
        | aac      | bb   | 2     | 1      |
        | acc      | cc   | 3     | 1      |
         ----------------------------------

script select data 

$data["adm"] = $this->db->where("level", "0")
                        ->or_where("level", "3")
                        ->where("status", "1")
                        ->get('tb_user_data')->result_array();

当我尝试按名称搜索时,脚本不起作用。或者我得到了一些错误的脚本或其他任何东西?

谢谢

【问题讨论】:

  • doesn't work 是程序员应该对其他程序员说的最糟糕的事情.. 代码不包括名称搜索.. 尝试添加 andWhere("name", [name])
  • 只需将语法内联写入一个函数where('(a or b) and c')
  • 你可以在 codeigniter 中 ->where_in 子句。请参阅下面的链接,这将对您有所帮助stackoverflow.com/questions/11023318/…
  • 顺便说一句,您可以在使用$this->db->last_query();查看结果之前调试您的sql
  • 谢谢各位,问题解决了

标签: php mysql database codeigniter


【解决方案1】:

试试这个:

$data["adm"] = $this->db->where_in('level', array('0','3'))
                        ->where("status", "1")
                        ->get('tb_user_data')->result_array();

【讨论】:

  • 欢迎@ImamNur。如果对您有帮助,请接受作为答案。 :)
猜你喜欢
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多