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

[eluser]Richko[/eluser]
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...
#2

[eluser]stuffradio[/eluser]
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.
#3

[eluser]ehicks727[/eluser]
I'd have a separate function in your model just to get the comment count.

Code:
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...
#4

[eluser]ehicks727[/eluser]
Then in your view, do something like this...

Code:
<?=$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.
#5

[eluser]Richko[/eluser]
thanks it worked for meSmile




Theme © iAndrew 2016 - Forum software by © MyBB