CodeIgniter Forums
join problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: join problem (/thread-9335.html)



join problem - El Forum - 06-22-2008

[eluser]Jim-Bingo[/eluser]
Hi!

I have a problem with my Join.

Code:
$this->db->select('*, news.date as newsdate, news.content as newscontent');
$this->db->from('news');
$this->db->join('news_comments', 'news_comments.nid = news.id');
$this->db->limit('3');
          
$query = $this->db->get();
          
return $query;

I want it to print out the news and all comments that belong to it.

Like this

News 1
comment
comment
comment

News 2
comment
comment

News 3
comment
comment

How do I do that?

Hope you understand. Sorry for my bad english.


join problem - El Forum - 06-22-2008

[eluser]Developer13[/eluser]
About the only thing I see wrong with the query as you have it is you don't have anything being explicitly selected from the news_comments table. Add news_comments.comment (or whatever) to your select statement. Otherwise, what specifically is the problem?


join problem - El Forum - 06-23-2008

[eluser]Jim-Bingo[/eluser]
I donĀ“t know how to print it out. I think I need to use two loops. One for the news and another one inside for the comments. Is that right?