Welcome Guest, Not a member yet? Register   Sign In
Use column name as the array key for db->result_array()
#1

[eluser]wyred[/eluser]
I'm trying to get some support for this feature: http://codeigniter.uservoice.com/forums/...sult-to-be

It's already available in Kohana framework ( http://kohanaframework.org/3.1/guide/dat...ct-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();
$result = array();
foreach($temp AS $t) {
  $result[$t['id']] = $t;
}
It's an extra step and more memory consumption.

If there's any negative side to this, I'd like to hear and learn about it.
#2

[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.
#3

[eluser]wyred[/eluser]
Really? There's no mention of it in the documentation, http://ellislab.com/codeigniter/user-gui...sults.html

And even when I look at the source code, the function doesn't accept any parameters.

Did I overlook something?
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB