Use column name as the array key for db->result_array() - 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: Use column name as the array key for db->result_array() (/showthread.php?tid=43192) |
Use column name as the array key for db->result_array() - El Forum - 07-03-2011 [eluser]wyred[/eluser] I'm trying to get some support for this feature: http://codeigniter.uservoice.com/forums/40508-codeigniter-reactor/suggestions/1561893-pass-column-name-into-active-record-result-to-be It's already available in Kohana framework ( http://kohanaframework.org/3.1/guide/database/results#select-asarray ). CI should have it to because it helps beginners like me to fix those "SQL N+1 SELECT problem" without writing complex join queries. My current workaround is to loop through those results again: Code: $temp = $rs->result_array(); If there's any negative side to this, I'd like to hear and learn about it. Use column name as the array key for db->result_array() - El Forum - 07-04-2011 [eluser]toopay[/eluser] Its already like that. When you use CI db lib/class, and retrieveing the result with result_array method, you get the result just like Kohana did with as_array. Use column name as the array key for db->result_array() - El Forum - 07-04-2011 [eluser]wyred[/eluser] Really? There's no mention of it in the documentation, http://ellislab.com/codeigniter/user-guide/database/results.html And even when I look at the source code, the function doesn't accept any parameters. Did I overlook something? Use column name as the array key for db->result_array() - El Forum - 07-04-2011 [eluser]toopay[/eluser] [quote author="wyred" date="1309797074"]...the function doesn't accept any parameters.[/quote] For that helpful feature, CI db indeed doesn't support. But create an extra function/helper (like your above code) to achieve that, will be consume same memory with Kohana DB class i believe. |