S
S
semki0962016-03-19 16:22:15
MySQL
semki096, 2016-03-19 16:22:15

How to count the number of articles using Codeigniter as an example?

Unable to count the number of articles in CI. I write in the model

public function get_count_comments($id)
        {       
                $query = $this->db->get_where('comments');
                echo $query->num_rows();
        }

In the controller
$data['count_comments'] = $this->comment_model->get_count_comments($id);

I get the output Where is my mistake? Thank you. "count_comments":null

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor, 2016-03-21
@egormmm

If you need to assign the result to a variable, as you do here:
then the get_count_comments($id) method should return a result.
So instead of echo writereturn $query->num_rows();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question