[eluser]TheFuzzy0ne[/eluser]
[quote author="davehedgehog" date="1365690149"]Im using MySql no Ajax.[/quote]
Hmm. Are comments viewed on a different page from the blog itself, or are you using a frame or something?
Code:
function get_comments()
{
// Here you're not passing an ID to get_comments().
// You're also using an extra variable unnecessarily.
$query = $this->blog_model->get_comments();
$data['comment'] = $query;
// This isn't being passed into the view, and has now been called twice.
// Where is $blog_item coming from?
$comments = $this->blog_model->get_comments($blog_item->id);
if(!$comments)
{
// This should be handled by your view.
echo 'No comments';
}
else
{
$this->load->view('blog/comments',$data);
}
}
Here are my proposed changes:
get_comments() controller method:
Code:
function get_comments($id = 0)
{
$data['comments'] = $this->blog_model->get_comments($id);
$this->load->view('blog/comments', $data);
}
View:
Code:
<?php if ($comments): ?><?php foreach($comments as $com): ?>
<table>
<tr><td>Date:<?php echo $com['name']; ?></tr>
<tr><td>Post:<?php echo $com['comment']; ?></tr>
<tr><td>Date:<?php echo $com['date']; ?></tr>
</table><?php endforeach;?><?php else: ?>
<p>
There are no comments for this blog.
</p><?php endif;?>
Your presentation logic should be within your view. Now you view decides what to do (if anything), when there are no comments.