Reuse Active Record query condition to get result and number of result |
[eluser]tkaw220[/eluser]
Considering I have below Model: Code: $this->db->select('id, title, format, property, isbn') Firstly, I extracted results by using Get. Next, I want to be able to calculate the number of results returned by the query but fail. How can I reuse the query, and get the result and number of results at the same time without having to rewrite the query condition again? Thanks in advanced.
[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...sults.html Code: $books = $this->db->get('products', $limit, $offset);
[eluser]tkaw220[/eluser]
Hi noctrum, Arr ... I totally forgot this useful function. Thanks for the help. Have a nice day.
[eluser]tkaw220[/eluser]
Hi notrum, Sorry for the mistake. The num_rows() did not solve my problem. My first get() function return query with limit (said 20), but I wish to be able to return all query which match the where() clause, said 86 for example. I am building my product page with pagination, and show 20 products at time. I want to show total 86 products for that brand on top. Below is my working code: Code: $where = array($type => urldecode($value), 'bookseller_access !=' => 'no'); The first line get() return query limited to $limit, and the second count_all_results() return exactly total books match the where() clause. I am wondering there is better way to do this instead of having two where() statement. Thank you.
[eluser]toopay[/eluser]
If the case is : you've use very very common where clause, until using general CI AR syntax become ineffective, you can always create a shorthand for that, as simply like Code: // In your model Code: $limit_products = $this->product_model->select_product()
[eluser]tkaw220[/eluser]
Hi toopay, Thanks for the trick. Now my code has became more reusable. Have a nice day. |
Welcome Guest, Not a member yet? Register Sign In |