开发者

codeigniter join problem

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`)
) ENG开发者_Go百科INE=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


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.


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");


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

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

and check what's wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜