CodeIgniter: help with this query
Posted
by
iamjonesy
on Stack Overflow
See other posts from Stack Overflow
or by iamjonesy
Published on 2011-01-08T00:05:02Z
Indexed on
2011/01/08
0:54 UTC
Read the original article
Hit count: 178
Hi,
I have just started my first CI app. I have a view that displays some posts. Each post can have multiple comments and I want to display the total number of comments next to each post.
So far all my db call are in my controller (will be changing this).
function index(){
$data['query'] = $this->db->get('posts');
$this->load->view('blog_view', $data);
}
In my view:
<?php foreach($query->result() as $row):
<div class="post-box">
<p><?php echo $row->body; ?><small> added by <?php echo $row->username; ?> on <?php echo date ('d/m/Y',strtotime($row->created)); ?> <a href="<?php echo base_url(); ?>blog/comments/<?php echo $row->id; ?>"><img src="<?php echo base_url(); ?>images/comments_icon.png" /> 0</a></small></p>
</div>
<?php endforeach; ?>
I want to get the total number of comments where comment.post_id = the current record's id. and display it next to the comments icon.
Any help with this most appreciated,
Billy
© Stack Overflow or respective owner