• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
join problem

#1
[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.

#2
[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?

#3
[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?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.