codeigniter加入问题

发布于 2024-10-11 16:23:47 字数 2842 浏览 4 评论 0原文

大家好,我有一个问题,当我尝试加入我的评论表时,它什么都不显示

,这是我的代码

$this->db->select('*,users.profil_billed as profil_billed, forum_traad.id as traad_id');
$this->db->from('forum_traad');
$this->db->join('users', 'forum_traad.brugernavn = users.username');
$this->db->where('forum_traad.fk_forum_kategori', $id);
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_kommentare.fk_forum_traad', 'forum_traad.id');
$this->db->order_by("forum_traad.id", "DESC");

,然后我将其放入其中,什么也不显示,我不知道为什么..我需要一些左连接、右连接等吗? ?我已经尝试了所有这些:d

$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_kommentare.fk_forum_traad', 'forum_traad.id');

kommentare = 评论 traad = 线程 布鲁格纳夫 = 用户名 kategori = 类别

其丹麦语,

抱歉我的英语不好希望有人可以帮助我


我的数据库结构是这样的,我使用mysql

CREATE TABLE `forum_kategori` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `kategori` text NOT NULL,
  `beskrivelse` mediumtext NOT NULL,
  `godkendt` varchar(4) NOT NULL DEFAULT 'ja',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;

CREATE TABLE `forum_kommentare` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fk_forum_traad` int(11) NOT NULL,
  `brugernavn` text NOT NULL,
  `indhold` mediumtext NOT NULL,
  `dato` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `time` text NOT NULL,
  `godkendt` varchar(4) NOT NULL DEFAULT 'ja',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28;

CREATE TABLE `forum_traad` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `overskrift` text NOT NULL,
  `indhold` mediumtext NOT NULL,
  `fk_forum_kategori` int(11) NOT NULL,
  `brugernavn` text NOT NULL,
  `dato` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `godkendt` varchar(4) NOT NULL DEFAULT 'ja',
  `time` text NOT NULL,
  `status` varchar(8) NOT NULL DEFAULT 'aaben',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4;

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(80) NOT NULL,
  `password` text NOT NULL,
  `kon` varchar(5) NOT NULL,
  `alder` text NOT NULL,
  `hood` varchar(4) DEFAULT NULL,
  `fornavn` varchar(60) DEFAULT NULL,
  `efternavn` varchar(100) DEFAULT NULL,
  `city` text,
  `ip` varchar(20) DEFAULT NULL,
  `level` text,
  `email` text,
  `point` int(11) NOT NULL,
  `oprettet` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `fritekst` mediumtext NOT NULL,
  `profil_billed` text NOT NULL,
  `online` varchar(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=31;

,它什么也不返回,也没有错误,它只显示一条我用 else 语句完成的消息,上面写着“有此类别中没有线程”,我尝试过左连接、右连接、内连接、全连接,是的,所有这些:S

Hello all i have a problem that when i try to join my comment table it show nothing

here is my code

$this->db->select('*,users.profil_billed as profil_billed, forum_traad.id as traad_id');
$this->db->from('forum_traad');
$this->db->join('users', 'forum_traad.brugernavn = users.username');
$this->db->where('forum_traad.fk_forum_kategori', $id);
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_kommentare.fk_forum_traad', 'forum_traad.id');
$this->db->order_by("forum_traad.id", "DESC");

its then i put this in it show nothing, and i dont know why.. do i need some left join, right join etc.? i have try all of it :d

$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_kommentare.fk_forum_traad', 'forum_traad.id');

kommentare = comments
traad = thread
brugernavn = username
kategori = categori

its danish,

sorry my bad english hope some one can help me out


my database structure is this and im using mysql

CREATE TABLE `forum_kategori` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `kategori` text NOT NULL,
  `beskrivelse` mediumtext NOT NULL,
  `godkendt` varchar(4) NOT NULL DEFAULT 'ja',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;

CREATE TABLE `forum_kommentare` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `fk_forum_traad` int(11) NOT NULL,
  `brugernavn` text NOT NULL,
  `indhold` mediumtext NOT NULL,
  `dato` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `time` text NOT NULL,
  `godkendt` varchar(4) NOT NULL DEFAULT 'ja',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28;

CREATE TABLE `forum_traad` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `overskrift` text NOT NULL,
  `indhold` mediumtext NOT NULL,
  `fk_forum_kategori` int(11) NOT NULL,
  `brugernavn` text NOT NULL,
  `dato` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `godkendt` varchar(4) NOT NULL DEFAULT 'ja',
  `time` text NOT NULL,
  `status` varchar(8) NOT NULL DEFAULT 'aaben',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4;

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(80) NOT NULL,
  `password` text NOT NULL,
  `kon` varchar(5) NOT NULL,
  `alder` text NOT NULL,
  `hood` varchar(4) DEFAULT NULL,
  `fornavn` varchar(60) DEFAULT NULL,
  `efternavn` varchar(100) DEFAULT NULL,
  `city` text,
  `ip` varchar(20) DEFAULT NULL,
  `level` text,
  `email` text,
  `point` int(11) NOT NULL,
  `oprettet` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `fritekst` mediumtext NOT NULL,
  `profil_billed` text NOT NULL,
  `online` varchar(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=31;

and it return nothing and no errors it only show a message i have done with a else statement that said "there is no threads on this categori", i have try with left join, right join inner join full join, ye all of it :S

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贪了杯 2024-10-18 16:23:47

您应该尝试在连接上使用 left 连接并从那里开始工作。如果这不起作用,那么表之间就没有链接。

You should try using a left join on your joins and work from there. If that doesn't work then there isn't a link between the tables.

尝蛊 2024-10-18 16:23:47

试试这个代码:

$this->db->select('*,users.profil_billed as profil_billed, forum_traad.id as traad_id');
$this->db->from('forum_traad');
$this->db->join('users', 'forum_traad.brugernavn = users.username');
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_traad.fk_forum_kategori', $id);
$this->db->order_by("forum_traad.id", "DESC");

Try this code:

$this->db->select('*,users.profil_billed as profil_billed, forum_traad.id as traad_id');
$this->db->from('forum_traad');
$this->db->join('users', 'forum_traad.brugernavn = users.username');
$this->db->join('forum_kommentare', 'forum_traad.id = forum_kommentare.fk_forum_traad');
$this->db->where('forum_traad.fk_forum_kategori', $id);
$this->db->order_by("forum_traad.id", "DESC");
原谅过去的我 2024-10-18 16:23:47

您可以在 $this->db->get() 之后使用

print $this->db->last_query();

并检查有什么问题。

You can use after $this->db->get() the

print $this->db->last_query();

and check what's wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文