CodeIgniter Forums
Extenstion of blog tutorial -> Counting the Comments - 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: Extenstion of blog tutorial -> Counting the Comments (/showthread.php?tid=2522)



Extenstion of blog tutorial -> Counting the Comments - El Forum - 08-10-2007

[eluser]Freakish_05[/eluser]
Good morning everyone!

I've been trying to extend the blog video tutorial a bit by adding a count of the comments for a particular blog entry (i.e. "There are X comments")

I've been trying to add a count into my SQL query for all the comments where entry_id matches the blog id. This shows no sign of working :long:

Any suggestions on how I could accomplish this would be very much appreciated.

Regards,
Freakish_05


Extenstion of blog tutorial -> Counting the Comments - El Forum - 08-10-2007

[eluser]deviant[/eluser]
The SQL query I was using for counting comments on news items was something along the lines of

Code:
SELECT news.*, COUNT(comment.id) AS num_comments FROM news LEFT JOIN comment ON (comment.post_id=news.id) GROUP BY news.id ORDER BY news.date_posted DESC



Extenstion of blog tutorial -> Counting the Comments - El Forum - 08-10-2007

[eluser]Freakish_05[/eluser]
Thanks for that deviant!

I cut your code a bit but it works great! Thanks so much!

Freakish_05