2015-11-24 84 views
0

你好,我想加入三個表,但它從用戶表中獲取所有數據,我只想要firstname和lastname參數如何從codeigniter中的連接表中獲取有限的數據參數?

這是我的連接查詢。我想要像加入(user.firstname)的東西。

$this->db->select('*'); 
    $this->db->from('post'); 
    $this->db->join('user', 'user.id = post.cop_id'); 
    $this->db->join('source', 'post.source_id = source.id'); 
    $query = $this->db->get(); 
    return $query->result(); 

回答

3

你可以做這樣的事情:

$this->db->select('post.*, source.*, user.firstname, user.lastname'); 
$this->db->from('post'); 
$this->db->join('user', 'user.id = post.cop_id'); 
$this->db->join('source', 'post.source_id = source.id'); 
$query = $this->db->get(); 
return $query->result(); 

表。*表示您需要該表中的所有字段。

+0

感謝您對我的迴應:) – yogendrayaduvanshi

0

變化$this->db->select('*');$this->db->select('user.firstname, user.lastname');

相關問題