2015-11-24 45 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');

相关问题