I am trying to use the count_all()
method in kohana 3.3 to count all the rows of a table where the id equals a user_id
. Here is my controller
public function action_get_messages()
{
$user_id = $this->request->param('id');
$messages = new Model_Message;
if ($user_id)
{
$messages = $messages->where('user_id', '=', $user_id);
$messages->reset(FALSE);
$message_count = $messages->count_all();
}
else
{
$message_count = $messages->count_all();
}
$pagination = Pagination::factory(array(
'total_items' => $message_count,
'items_per_page' => 3,
));
$pager_links = $pagination->render();
$messages = $messages->get_all($pagination->items_per_page, $pagination->offset, $user_id);
$this->template->content = View::factory('profile/messages')
->set('messages', $messages)
->set('pager_links', $pager_links);
}
But when i run the code i get these error message:
"Database_Exception [ 1054 ]: Unknown column 'COUNT("*")' in 'field list' [ SELECT
COUNT("*")
ASrecords_found
FROMmessages
ASmessage
WHEREuser_id
= '2' ]"
What does this error mean and where is the error in my code? Thanks in advance!