Basic question about count_all_results() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Basic question about count_all_results() (/showthread.php?tid=19825) |
Basic question about count_all_results() - El Forum - 06-19-2009 [eluser]Unknown[/eluser] Hello everybody, I have a simple question about the count_all_results method of Active Record. I have 2 entries in my table (returned by the following query): Code: $data['query'] = $this->db->get_where('produits', array('categories_id' => $this->uri->segment(3))); And, when I put the total in the following variable: Code: $data['total'] = $this->db->count_all_results(); I'm always getting 1 instead of 2. Do you guys have an idea? Thanks. Basic question about count_all_results() - El Forum - 06-19-2009 [eluser]bretticus[/eluser] Would your where clause that specifies a single categories_id not return a single result??? Perhaps you meant... Code: $data['total'] = $this->db->count_all_results('produits'); ...or... Code: $data['total'] = $this->db->count_all('produits'); Basic question about count_all_results() - El Forum - 06-19-2009 [eluser]TheFuzzy0ne[/eluser] I'm surprised you're getting anything at all. I think you might find this works as expected: Code: $where = array('categories_id' => $this->uri->segment(3)); Basic question about count_all_results() - El Forum - 06-19-2009 [eluser]Jailbird[/eluser] Code: $data['query'] = $this->db->where('categories_id',$this->uri->segment(3)); Basic question about count_all_results() - El Forum - 06-19-2009 [eluser]TheFuzzy0ne[/eluser] Uhm... Other than the error in the top line of code, how is that any different from what the OP is doing? Basic question about count_all_results() - El Forum - 06-19-2009 [eluser]Jailbird[/eluser] Correct me if I'm wrong, but up to my knowledge, Code: $data['query'] = $this->db->where('categories_id',$this->uri->segment(3)); Code: $data['query'] = $this->db->where('categories_id',$this->uri->segment(3)); Code: SELECT COUNT(*) AS `numrows` FROM (`produits`) WHERE `categories_id` = '$this->uri->segment(3)' Whereas the OP's, Code: $data['query'] = $this->db->get_where('produits', array('categories_id' => $this->uri->segment(3))); Code: SELECT * FROM (`produits`) WHERE `user_type_id` = '$this->uri->segment(3)' Seems like a working solution, but might be I'm not using a pattern efficient enough? |