Welcome Guest, Not a member yet? Register   Sign In
Want to add a count to the # of comments
#1

[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>&lt;?=$row->title?&gt;</h2>

    <p>&lt;?=character_limiter("$row->body", 100);?&gt;</p>
    <p>Author: &lt;?=$row->first_name.' '.$row->last_name?&gt;</p>
    <p>&lt;?=anchor('blog/more/'.$row->id, 'Read on');?&gt;</p>
    <p>&lt;?=anchor('blog/comments/'.$row->id, 'Comments');?&gt;</p>
    <hr>
&lt;?php endforeach; ?&gt;

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.


Messages In This Thread
Want to add a count to the # of comments - by El Forum - 12-22-2008, 10:31 PM
Want to add a count to the # of comments - by El Forum - 12-22-2008, 10:55 PM
Want to add a count to the # of comments - by El Forum - 12-23-2008, 09:07 AM
Want to add a count to the # of comments - by El Forum - 12-23-2008, 10:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB