【问题标题】:how can i pass array in where clause with codeigniter?如何使用codeigniter在where子句中传递数组?
【发布时间】:2016-11-02 15:16:37
【问题描述】:

如何使用 codeigniter 在 where 子句中传递数组变量? 例如,使用如下 SQL 查询:

Select(" item,price Where(userid=123 and proid=3 or userid=124 and proid=3... [upto n user id]userid=nth_id and proid=3");

如果 userid 存储在数组变量中,那么如何在 codeigniter 中创建这样的条件?

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    我正在寻找这个,它应该寻找数组中的userid,并且proid 为 3。我尚未对其进行测试,但请告诉我们您的进展情况。

    $array = array( '123', '124' );
    $this->db
         ->select( 'item, price' )
         ->from( 'table')
         ->where( 'proid', '3' )
         ->where_in( 'userid', $array )
         ->get();
    $result = $query->result();
    

    【讨论】:

      猜你喜欢
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-27
      • 2018-07-17
      相关资源
      最近更新 更多