有人可以告诉我如何正确地写这个吗?
function get_tech() {
$this->db->select('u.id
,u.first_name
,us.id
,us.group_id');
$this->db->from('users u');
$this->db->join('users_groups us','us.id = u.id','left');
$records = $this->db->where('us.group_id', '3');
$data=array();
foreach($records->result() as $row)
{
$data[$row->id] = $row->first_name;
}
return ($data);
}
我正在尝试使用数组填充下拉菜单,但我只需要抓取属于users_group / group_id = 3的用户
因此,在我非常有限的知识中,我需要:select X from Users LEFT JOIN users_groups WHERE group_ID = 3
答案 0 :(得分:2)
您需要致电$this->db->get()
才能实际运行查询。
function get_tech() {
$this->db->select('u.id
,u.first_name
,us.id
,us.group_id');
$this->db->from('users u');
$this->db->join('users_groups us','us.id = u.id','left');
$this->db->where('us.group_id', '3');
$records = $this->db->get();
$data = array();
foreach($records->result() as $row){
$data[$row->id] = $row->first_name;
}
return $data;
}