Php 代码点火器连接问题
我想从3个表中选择“Forum\u traad”“Forum\u kommentare”“users” 我想收集“forum_traad”和“forum_kommentare”中的所有字段,只收集我的用户表中的字段“profil_billed”,我想显示适合创建线程的用户以及在线程中创建响应的用户的图片 我在“forum_traad”和“forum_kommentare”中有一个字段,叫做“Brugernavn”,它必须与“users”表中的“Brugernavn”匹配 希望你明白我的意思,这就是我迄今为止所做的: 模型文件:Php 代码点火器连接问题,php,mysql,codeigniter,Php,Mysql,Codeigniter,我想从3个表中选择“Forum\u traad”“Forum\u kommentare”“users” 我想收集“forum_traad”和“forum_kommentare”中的所有字段,只收集我的用户表中的字段“profil_billed”,我想显示适合创建线程的用户以及在线程中创建响应的用户的图片 我在“forum_traad”和“forum_kommentare”中有一个字段,叫做“Brugernavn”,它必须与“users”表中的“Brugernavn”匹配 希望你明白我的意思,这就
$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();
我的视图文件:
if($query)
{
echo $query->overskrift;
} else {
echo "der er ikke noget";
}
一条简单的建议:当你发布问题时,试着将数据(代码)改成英语。。。并描述一些参数-数据在你的程序中的含义,db表中的关系,fk-s…在这种情况下,更多的人会试图帮助你,他们的一些事情看起来比他们必须破译这里发生的事情更明显 因此,我将尽力帮助: 这是您的echo sql:
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
FROM (forum_traad)
JOIN forum_kommentare ON forum_kommentare.fk_forum_traad = forum_traad.id
JOIN users ON forum_traad.brugernavn = users.profil_billed
WHERE forum_traad.id = '5'
从丹麦语(我想)到英语的翻译如下:
SELECT *, forum_thread.content as thread_content,
forum_comments.content as comments_content,
forum_thread.user as thread_user,
forum_thread.id as thread_id,
users.profil_image as image
FROM (forum_thread)
LEFT JOIN forum_comments
ON forum_comments.fk_forum_thread = forum_thread.id
LEFT JOIN users
ON forum_thread.user = users.profil_image
WHERE forum_thread.id = '5'
在上次联接中,您将联接图像列?上的用户表?。。请尝试:
LEFT JOIN users
ON forum_comments.user = users.id
在这种情况下,你会得到所有在帖子中发表评论的人(包括主海报,因为他的帖子是第一个?)
我不确定这是否是正确的解决方案(答案)。如果它不是张贴您的评论在这里,我们将尽力帮助