[eluser]Brad Morse[/eluser]
I want to add the number of comments for each blog entry.
Here is my controller for the index that displays each entry with a link to view all the comments, which I want the # of comments to be next to the comments link.
Code:
function index() {
$data['title'] = "My Blog Title";
$data['heading'] = "My Blog Heading";
//$data['query'] = $this->db->get('entries');
$this->db->select('*');
$this->db->from('entries');
$this->db->join('authors', 'authors.id = entries.id', 'inner');
//$this->db->join('user as user1', 'entries.author_id = authors.id');
$data['query'] = $this->db->get();
$this->load->view('blog_view', $data);
}
Here is the code for the view:
Code:
<?php foreach($query->result() as $row): ?>
<h2><?=$row->title?></h2>
<p><?=character_limiter("$row->body", 100);?></p>
<p>Author: <?=$row->first_name.' '.$row->last_name?></p>
<p><?=anchor('blog/more/'.$row->id, 'Read on');?></p>
<p><?=anchor('blog/comments/'.$row->id, 'Comments');?></p>
<hr>
<?php endforeach; ?>
Right now it displays a link "Comments" which is linked to /blog/more/1 <-- 1 being the entry id, more being the more_view.php to display the entire entry w/ all the comments.
Which works great, but I want to add the # of comments next to the comments link that you see within the view code.
so it would go from "Comments" to "Comments (4)" <-- 4 being the number of comments that entry has.
The tables: comments.entry_id == entries.id
Any help is appreciated.