Hello!
I followed this topic: /topic/1963-simple-guide-to-executing-custom-queries/
to learn how to use custom queries. It's great!
The problem is that the results did not respect pagination, so even when you have max 10 lines per page, it shows all the results. After some struggling, I managed to get the pagination working adding the 'limit' and 'get_total_results' functions. So if anyone is having this problem, the custom_model gets like this:
class Custom_Query_model extends grocery_CRUD_Model { private $query_str = ''; function __construct() { parent::__construct(); } function get_list() { $query = $this->db->query($this->query_str); $results_array = $query->result(); return $results_array; } public function set_custom_query($query_str) { $this->query_str = $query_str; } /* Adding this does the trick for limiting the results per page! */ function limit($value, $offset = ''){ $this->query_str .= ' LIMIT '.($offset ? $offset.', ' : '').$value; } /* This method is to count the results of your query. If you don't add this * the total results on 'Displaying 1 to n of x items' can be wrong, 'cause * grocery will get the total amount of rows from the table */ function get_total_results() { return count($this->get_list()); }
I tested in some of my tables that use custom query, and it's all good, but if anyone has other solution or find some error, please let me know.
PS.: I'm creating new topic because the other one is a little old and it's not about pagination. Thank you very much!