How to execute 2 queries with the same settings? |
[eluser]chefnelone[/eluser]
Hello I need to make 2 queries with the same settings: If I do this: Code: $this->db->order_by('order', 'asc'); //SETTING FOR THE QUERY the FIRST REQUEST takes the setting of the query: order_by and like but then the SECOND REQUEST doesn't take those settings of the query again. I mean: the request: $this->db->count_all_results('products'); generate this query: Code: SELECT COUNT(*) FROM (`products`) WHERE `product_name` LIKE '%shoes%' ORDER BY `orden` asc; Code: SELECT * FROM (`products`) LIMIT 10; Code: SELECT * FROM (`products`)WHERE `product_name` LIKE '%shoes%' ORDER BY `orden` asc; LIMIT 10 It's like I need to set up again order_by and like after a request.??
[eluser]chefnelone[/eluser]
[quote author="n0xie" date="1280844413"]That's because you have to set it up again.[/quote] and is there any way to save the query and use it again using actives records?
[eluser]Clooner[/eluser]
[quote author="chefnelone" date="1280844641"]and is there any way to save the query and use it again using actives records?[/quote] Isn't that why they invented procedures, functions and methods... Code: function basicquerysettings()
[eluser]Clooner[/eluser]
[quote author="n0xie" date="1280845541"]Or use named scopes as Jamie has named them.[/quote] yes, using named scopes is the way to go!
[eluser]chefnelone[/eluser]
[quote author="n0xie" date="1280845541"]Or use named scopes as Jamie has named them.[/quote] This seems to be a good one to me. thanks
[eluser]mddd[/eluser]
CI has its own "caching" in the active record class. It is not real caching, but more like remembering of settings. Exactly what you are looking for. Code: $this->db->start_cache();
[eluser]chefnelone[/eluser]
[quote author="mddd" date="1280847738"]CI has its own "caching" in the active record class. It is not real caching, but more like remembering of settings. Exactly what you are looking for. Code: $this->db->start_cache(); you're right moddd this is what I was looking for. Many thanks.
[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...ecord.html Quote:$this->db->count_all_results(); |
Welcome Guest, Not a member yet? Register Sign In |