Welcome Guest, Not a member yet? Register   Sign In
help with blog model

hi i am new to ci, so i am trying to code blog.

i have blog model

function get_entries() {
$this->db->orderby('id', 'DESC');
$query = $this->db->get('blog_entries');
foreach ($query->result_array() as $row)
$result[] = $row;
return $result;

i want to get comments count for each entry and send to view, but i dont realise how to do this...

If you just want to know how many comments it has.. you don't need all that.

First tell me how your table is laid out, and how you're storing your comments.

I'd have a separate function in your model just to get the comment count.

function getCommentCount($article_id) {
        $query = $this->db->query("SELECT COUNT(id) AS count FROM database.table WHERE article_id = ".$article_id.";");
        return $query->row();

or something like that...

Then in your view, do something like this...

<?=$this->modelname->getCommentCount($article_id)->count ?>

I'm doing that off the top of my head, so someone please correct if I hosed it up.

thanks it worked for meSmile

Theme © iAndrew 2016 - Forum software by © MyBB