首页 文章

如何从codeigniter中的连接表中获取有限的数据参数?

提问于
浏览
0

您好我想加入三个表,但它从用户表中获取所有数据,我只想要firstname和lastname参数

这是我的连接查询 . 我想要一些像join(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 回答

  • 0

    你可以这样做:

    $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

    $this->db->select('*'); 更改为 $this->db->select('user.firstname, user.lastname');

  • 3

    您可以在选择中定义:

    $this->db->select(['post.id', 'post.title', 'post.description', 'user.firstname']);
    

    看看这个答案https://stackoverflow.com/a/15402766/1897484

相关问题