Welcome Guest, Not a member yet? Register   Sign In
noob - Video Tutorial Blog Extension - How to count number of comments?
#1

[eluser]loopymonkey[/eluser]
Learning to use CI and after following the blog tutorial was looking to understand how to extend:

How do I go about adding a number next to comments that would count only the number of entries related to that comment id?

Thanks!
#2

[eluser]Doncqueurs[/eluser]
It is not entirely clear what your exact question is. But here two answers that go into the direction (I hope and think)

An SQL query counting the comments for a particular post. This will give you a number that represents the comments of a particular post :
Quote:SELECT count() FROM comments WHERE post_id = 'x'

Or if you want to number the comments on your webpage you can also use an ordinary ordered-list (<ol></ol>) and then put every comment in a <li></li>
#3

[eluser]loopymonkey[/eluser]
Thanks for the reply. in the video tutorial you end up with a link under each blog entry that says 'comments' and when you click that it goes to the comments page and lists out all the comments. I wanted to add a number next to that comments link so it would let the user know how many comments are contained on the next page. I was trying to figure out how to add that code in the view and controller. I'll try the code. Thanks!
#4

[eluser]Doncqueurs[/eluser]
OK, then the simple ordered list would do the job! Or something simple like:

Code:
$count = '1';
foreacht(){
echo $count;
echo $author;
echo  #comment;
$count++
}

This is especially useful if you want a bit more freedom than the ordered list.
#5

[eluser]Michael Wales[/eluser]
You had it right the first time Donc (your second solution is numbering the individual comments).

Just query the database to count, from within your controller, and add that value to your $data array/object. Then echo that value out within your view.
#6

[eluser]loopymonkey[/eluser]
Both very helpful thanks!




Theme © iAndrew 2016 - Forum software by © MyBB