![]() |
$this->db->count_all_results() returning 1 instead of 0 - 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: $this->db->count_all_results() returning 1 instead of 0 (/showthread.php?tid=53573) |
$this->db->count_all_results() returning 1 instead of 0 - El Forum - 07-30-2012 [eluser]thisischris[/eluser] I have the following code in a library: Code: private $CI; The database is completely empty yet rowCount is being set as 1? $this->db->count_all_results() returning 1 instead of 0 - El Forum - 07-30-2012 [eluser]tpetrone[/eluser] Start with simply: Code: echo $this->CI->db->count_all_results(); that should display the count.. Perhaps modify the if statement to: Code: if($rowCount >= 1) That might get you down the road. $this->db->count_all_results() returning 1 instead of 0 - El Forum - 07-30-2012 [eluser]NeoArc[/eluser] Don't use get_where (LIMIT 1, OFFSET 0) and count_all_results() at the same time. Use ->where() instead ![]() $this->db->count_all_results() returning 1 instead of 0 - El Forum - 07-30-2012 [eluser]Aken[/eluser] Don't use count_all_results() in the first place, because if you want to do that AND return a row, you'll need to run two queries. Use $query = get_where(...), and then $query->num_rows() to check the rows returned. |