Pass array to where in Codeigniter Active Record

前端 未结 4 1846
傲寒
傲寒 2020-12-05 22:50

I have a table in my database with adminId and clientId

There might be 20 records with the adminId of the logged in user and I\'m trying to pull a list of clients.

相关标签:
4条回答
  • 2020-12-05 23:40
    $this->db->where_in('id', ['20','15','22','42','86']);
    

    Reference: where_in

    0 讨论(0)
  • 2020-12-05 23:46

    Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with AND if appropriate,

    $this->db->where_in()
    ex :  $this->db->where_in('id', array('1','2','3'));
    

    Generates a WHERE field IN (‘item’, ‘item’) SQL query joined with OR if appropriate

    $this->db->or_where_in()
    ex :  $this->db->where_in('id', array('1','2','3'));
    
    0 讨论(0)
  • 2020-12-05 23:47

    From the Active Record docs:

    $this->db->where_in();
    

    Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate

    $names = array('Frank', 'Todd', 'James');
    $this->db->where_in('username', $names);
    // Produces: WHERE username IN ('Frank', 'Todd', 'James')
    
    0 讨论(0)
  • 2020-12-05 23:53

    Use where_in()

    $ids = array('20', '15', '22', '46', '86');
    $this->db->where_in('id', $ids );
    
    0 讨论(0)
提交回复
热议问题