How to execute 2 queries with the same settings? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to execute 2 queries with the same settings? (/showthread.php?tid=32743) |
How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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.?? How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [eluser]n0xie[/eluser] That's because you have to set it up again. How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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? How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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() How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [eluser]n0xie[/eluser] Or use named scopes as Jamie has named them. How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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! How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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 How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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(); How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [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. How to execute 2 queries with the same settings? - El Forum - 08-03-2010 [eluser]danmontgomery[/eluser] http://ellislab.com/codeigniter/user-guide/database/active_record.html Quote:$this->db->count_all_results(); |