Cách join nhiều bảng với nhau :))

public function getJobFold($n_order, $order,$limit)
{
    $this->db->select('un.title as title_un,un.id,me.name as name_me, tw.name as name_tw, pr.name as name_pr, un.expdate');
    $this->db->from('user_news un');
    $this->db->join('my_exp me', 'me.id = un.exp');
    $this->db->join('type_work tw','tw.id = un.career');
    $this->db->join('province pr','pr.id = un.province_id');
    $this->db->where('active','3');
    $this->db->order_by($n_order, $order);
    $this->db->limit($limit); 
    $query = $this->db->get();
    return $query->result_array();
}

Với cách này chúng ta phải dùng

$this->db->from('user_news un');

Đối với cách sau chúng ta không cần sử dụng $this->db->from('user_news un'); nữa mà thay vào đó ta gị trực tiesp trong $query = $this->db->get();

public function getJobFold($n_order, $order,$limit)
{
    $this->db->select('user_news.title,user_news.id,user_news.description,company_profiles.name_company');
    $this->db->join('company_profiles', 'company_profiles.company_id = user_news.user_id');
    $this->db->where('active','3');
    $this->db->order_by($n_order, $order);
    $query = $this->db->get('user_news',0,$limit);
    return $query->result_array();
}

Last updated

Was this helpful?