select after count - 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: select after count (/showthread.php?tid=6570) |
select after count - El Forum - 03-04-2008 [eluser]Unknown[/eluser] Hi everyone! I have the following problem, which i could solve by a simple hack , but i don't want to do it this way. I'm building results for a complex search form, so after each active record where, in the end i am in the situation in which: 1) i need the count for all the results 2) i want to select only the current set (limit) The problem is that, after $this->db->count_all_results(); the db object is reseted, so i would have to rebuild the query, which i don't like. (after that i add the limit and use $this->db->get() for the results). Any suggestions? Thanks! select after count - El Forum - 03-04-2008 [eluser]xwero[/eluser] from version 1.6.1 there is a cache functionality for the AR library to remember previously set variables that build the sql statement select after count - El Forum - 03-04-2008 [eluser]Armchair Samurai[/eluser] Just to give a quick example of what xwero's talking about: Code: $data = new stdClass; select after count - El Forum - 03-05-2008 [eluser]Unknown[/eluser] Ok, it worked quite nice this way. Thanks everyone! select after count - El Forum - 03-06-2008 [eluser]kjackson7_93[/eluser] If you want the count of the number of rows that would have been returned if you didn't have the limit clause, you can do: Code: MODEL... Look at the mysql docs for SQL_CALC_FOUND_ROWS. select after count - El Forum - 03-06-2008 [eluser]louis w[/eluser] [quote author="Armchair Samurai" date="1204664601"]Just to give a quick example of what xwero's talking about: Code: $data = new stdClass; Does the second db->select inherit the from and where from the first one? Not 100% sure how this works, looks very cool thou. select after count - El Forum - 08-24-2009 [eluser]BobbyB[/eluser] [quote author="Armchair Samurai" date="1204664601"]Just to give a quick example of what xwero's talking about: Code: $data = new stdClass; You are a genius! :-) |