[eluser]kaos78414[/eluser]
I'm trying to get a simple comment count for the front page to show the count next to the read more, but I'm having a bit of trouble.
The code in my controller pulling the blogposts looks like this:
Code:
function index() {
// $this->output->enable_profiler(TRUE);
$data['js'] = '[removed][removed]';
$data['post'] = $this->blogmodel->get_limited($limit = 5);
$data['body'] = 'blogview';
$data['count'] = $this->commentmodel->get_comment_count($blog_id);
if ($data['count'] == 1) {
$data['comments'] = 'Comment';
}
else {
$data['comments'] = 'Comments';
}
$this->load->view('includes/template', $data);
}
The get_comment_count function is a simple return num rows in my commentmodel:
Code:
function get_comment_count($blog_id) {
$this->db->where('blogid', $blog_id);
$q = $this->db->get('blogcomments');
return $q->num_rows();
}
Codeigniter returns this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: blog_id
Filename: controllers/blog.php
Line Number: 31
The thing is, I can't think of a way to define it correctly. I've tried a few things but with undesirable results. Any help is appreciated!
(Btw, I'd like to take a moment here to comment on how amazing the codeigniter community has been with me. I ask a lot of questions and I have never gotten a rude response. People always seem eager to help and I love that! Thanks guys!)