Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
codeigniter多连接_Codeigniter_Join - Fatal编程技术网

codeigniter多连接

codeigniter多连接,codeigniter,join,Codeigniter,Join,您好,我有这个加入,但我想加入另一个名为“用户”的选项卡,我想加入“profil_billed”行,我该怎么做 我的意思是“WHERE forum\u traad.brugernavn=users.profil\u billed”之类的 function posts($id) { $this->db->select('*,forum_traad.indhold as traad_indhold, forum_kommentare.

您好,我有这个加入,但我想加入另一个名为“用户”的选项卡,我想加入“profil_billed”行,我该怎么做

我的意思是“WHERE forum\u traad.brugernavn=users.profil\u billed”之类的

function posts($id)
{
    $this->db->select('*,forum_traad.indhold as traad_indhold,
                       forum_kommentare.indhold as kommentare_indhold,
                        forum_traad.brugernavn as traad_brugernavn,
                        forum_traad.id as traad_id
                       ');
    $this->db->from('forum_traad');
    $this->db->join('forum_kommentare', 'forum_kommentare.fk_forum_traad', 'forum_traad.id');
    $this->db->where('forum_traad.id', $id);

    $query = $this->db->get();

    if($query->num_rows > 0)
    {
        return $query->row();
    } else {
        return false;
    }

}

您可以按以下方式编写查询-

    $this->db->select('*,forum_traad.indhold as traad_indhold,
                       forum_kommentare.indhold as kommentare_indhold,
                        forum_traad.brugernavn as traad_brugernavn,
                        forum_traad.id as traad_id, users.profil_billed as billed
                       ');
   $this->db->from('forum_traad');
   $this->db->join('forum_kommentare', 'forum_kommentare.fk_forum_traad = forum_traad.id');
   $this->db->join('users', 'forum_traad.brugernavn = users.profil_billed');
   $this->db->where('forum_traad.id', $id);
   $query = $this->db->get();
有关我使用的语法的详细文档,请参阅下文-


类似的$this->db->join('users','forum\u traad.brugernavn','users.username');但是它不起作用,我可以有两个这样的连接吗?它不起作用,它转到我视图文件中的我的其他位置,看起来是这样的:你是得到了一个mysql错误还是返回了零行?你需要非自然连接吗,比如左连接?我只得到这个“Der blev ikke fundet nogen tråd”,那是我的else,所以没有。。我不知道我是否需要加入