Adding number of comments to blog tutorial. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Adding number of comments to blog tutorial. (/showthread.php?tid=4063) |
Adding number of comments to blog tutorial. - El Forum - 11-05-2007 [eluser]tirithen[/eluser] I'm trying to learn to think in the terms of controller and viewer, so as an exercise I'm trying to add feautres to the blog as shown in the video tutorial. Now I'm trying to add the number of comments to each post like 'Comments (8)' to the app so I changed the anchor to: Code: <p><?=anchor('blog/comments/'.$row->id,'Comments ('.$query2->num_rows(where('entry_id', $this->uri->segment(3))).')');?></p> I allso added a db connection to Code: $query2 What would be a good solution to this? Could I write a function that I run before the blog_view controller that stores the numer of comments per each posts in an array, could end up being a large array. Should I add a table on the sql server that keeps the count. Any thoughts is welcome, this is what my blog_view file looks like now (non working anchor) Code: <html> Adding number of comments to blog tutorial. - El Forum - 11-05-2007 [eluser]ELRafael[/eluser] what you can do controller file Code: $comments = $this->db->getwhere('comments', array('post_id' => $this->uri->segment(3))); Where: - comments your table - post_id the id of post that comment below - $this->uri->segment(3) the id of post that you show in foreach loop Get it? |