![]() |
Cannot make num_rows work - 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: Cannot make num_rows work (/showthread.php?tid=55242) |
Cannot make num_rows work - El Forum - 10-16-2012 [eluser]huskyfritz[/eluser] Hello guys, I am newbie in codeigniter and I am developing a simple site using this framework. Well I am trying to use num_rows to get all records in an array but still no luck. here's my codes: Code: $query_array = $this->db->query('SELECT STATEMENT'); Is it correct? Is there any simpliest way to achieve this? Thanks much! ![]() Cannot make num_rows work - El Forum - 10-16-2012 [eluser]Beginers[/eluser] num_rows will just get the number of rows affected not the value it contains use Code: $query_array->result_array(); Code: $query_array->num_rows() to get the desired output you want. Cannot make num_rows work - El Forum - 10-16-2012 [eluser]huskyfritz[/eluser] your suggestion did not work.. when I tried Code: $query_array = $this->db->query("SQL HERE"); it only displays "Array" word.. Thanks anyway ![]() Cannot make num_rows work - El Forum - 10-16-2012 [eluser]Beginers[/eluser] to test if it really get the values use Code: print_r($query_array->result_array()); Cannot make num_rows work - El Forum - 10-16-2012 [eluser]huskyfritz[/eluser] Yes, lots of records.. My code using num_rows is same as it showed in codeigniter documentation. The documentation says like this: Code: $query = $this->db->query('SELECT * FROM my_table'); and here's my code: Code: $query_array = $this->db->query('SELECT STATEMENT'); do u know what's wrong with my code? Thanks Cannot make num_rows work - El Forum - 10-16-2012 [eluser]CroNiX[/eluser] try echoing $query->num_rows() and then die() right after. BTW: num_rows() will be an integer that tells the number of rows your query returned. It's not the actual results. Cannot make num_rows work - El Forum - 10-17-2012 [eluser]huskyfritz[/eluser] Thanks CroNiX. Its working fine now. Cannot make num_rows work - El Forum - 10-17-2012 [eluser]Beginers[/eluser] of course the data will not display because you did not specify the fields that you want to display: try to display it all using foreach loop Code: $query = $this->db->query('SELECT * FROM my_table'); |