Best way to create an array with query 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: Best way to create an array with query results! (/showthread.php?tid=13175) |
Best way to create an array with query results! - El Forum - 11-13-2008 [eluser]daweb[/eluser] Usually.. excuse me about english :-( I have a dynamic query with some field results (maybe cod, title) or (maybe cod, title, order) or etc... It depends on the query. I want to build an array with the result of query $myarray = [title] = 'MyTitle' [cod] = 'MyCod' ext... Now, in my model code: Code: $query = $this->db->get('table'); // with some where clauses And in my library code: Code: $result = $this->CI->layout_Model->get_my_query(); Code: $result['result'][0]->$field Is it the best way to do that? Please help me CI people! Thank you guys PS. It works, I wanna know if it is elegant and the best way to do that Best way to create an array with query results! - El Forum - 11-13-2008 [eluser]daweb[/eluser] Ehi, I think this is the better solution, I hope: Code: foreach($result['result'] as $res => $row) : |