[eluser]LuckyFella73[/eluser]
Ah ok - I thought it should be displayed under a single blog entry ..
What you can do is doing the loop in your model push the values
into an array and get the number of comments while looping
Basically like this:
Code:
function get_entries($limit='') /* gets a list of blogitems, limit can be specified */
{
if(empty($limit)){
$this->db->select('*')->from('blog_entries')->join('blog_categories', 'blog_categories.category_id = blog_entries.entry_parent_id')->order_by('entry_id','desc');
$query = $this->db->get();
}
else
{
$this->db->select('*')->from('blog_entries')->join('blog_categories', 'blog_categories.category_id = blog_entries.entry_parent_id')->order_by('entry_id','desc')->limit($limit);
$query = $this->db->get();
}
if ($query->num_rows() > 0)
{
$blog_array = array();
foreach ($query->result_array() as $row)
{
# whatever fields you have
$blog_array['date'][] = $row['date'];
$blog_array['title'][] = $row['title'];
$blog_array['bodytext'][] = $row['text'];
$blog_array['number_of_comments'][] = $this->count_comments($id_blockentry); // provide the id of the blockentry the comments are related to here
}
}
return $blog_array;
}
function count_comments($id_blockentry = FALSE)
{
$this->db->where('comment_parent_id', $parent_id);
$this->db->from('comments');
return $this->db->count_all_results();
}
You will have to adjust some values of the code according to your db table columns,
the part: "$this->count_comments($id_blockentry);" and add some if statements in case
there are no comments and so on. But in generall you could do it like this.
In your view file loop through the array returned by the model (pass from controller
to the view of course)
Hope that helps ..
Edit: fixed a typo in model code: '_' was missing (number_of_comments)