Answer the question
In order to leave comments, you need to log in
Query in the database - fetching and counting rows in one function?
I need to select the last 3 comments for each article. I do it like this.
public function get_stena_comments($id)
{
$limit = 3;
$query = $this->db->get_where('stena_comments', array('parent_id' => $id), $limit);
return $query->result_array();
}
public function get_count_comments($id)
{
$query = $this->db->get_where('stena_comments', array('parent_id' => $id));
return $query->result_array();
}
Answer the question
In order to leave comments, you need to log in
Purely logically think how mysql will give you both 3 comments and the total number?
You can do without two functions, but without two requests - no ( no perversions )
Can. Just request ALL comments sorted by id or date, then count their number and take the last 3. All.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question