Simple Question: Expanding on the Blog Tutorial - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Simple Question: Expanding on the Blog Tutorial (/showthread.php?tid=27519) |
Simple Question: Expanding on the Blog Tutorial - El Forum - 02-13-2010 [eluser]MT206[/eluser] Hi, I am new to CI and I am having trouble wrapping my head around some simple things. Right now all I am trying to do is just put the number of comments a blog post has under the post but for the life of me I cant figure out how to. I understand how you would do it with just PHP but obviously the point is to have CI make life easier so I am trying to use it. Any help would be much appreciated. Thanks For people not familiar with the blog video tutorial here is the controller code: Code: function Blog(){ and the blog view code: Code: <html> Simple Question: Expanding on the Blog Tutorial - El Forum - 02-13-2010 [eluser]Bainzy[/eluser] Hi, the simple way in which to show the number of comments is to modify the controller slightly, all you need to do is in the controller change the line that reads Code: $data['query'] = $this->db->get('comments'); to Code: $data['comments'] = $this->db->get('comments'); then on your view file have the following or something similar Code: <?php echo '<cite>'.count($comments).'</cite>'; ?> the simple count statement will count how many results are in the comments table. Hope this helps Simple Question: Expanding on the Blog Tutorial - El Forum - 02-13-2010 [eluser]MT206[/eluser] Thanks, I think I was just over thinking this. Simple Question: Expanding on the Blog Tutorial - El Forum - 02-14-2010 [eluser]MT206[/eluser] I have still not been able to get this to display the proper count. I might be misunderstanding what was shown in the above post but I do not think so. From the code examples given above I do not understand why I would be changing the 'query' to 'comments' as that seems arbitrary and when I do I get the error: undefined variable comments which makes sense since there is no 'comments' variable in the index function to pass to the view. For more information the comment view looks like this: Code: <html> And the Database setup is: entries id, title, body comments id, entry_id, author, body Would I need another table that contains both entry_id and comment_id? I do not see how I could use data from both tables without manually writing an SQL query involving a JOIN or actually having a column for comment count which seems clunky. Simple Question: Expanding on the Blog Tutorial - El Forum - 02-15-2010 [eluser]atno[/eluser] Try this code Code: function total_comments() Edit: i don't have the time to create the blog tutorial again so i haven't test this code |