Welcome Guest, Not a member yet? Register   Sign In
Fetch result row as numeric index
#1

[eluser]Mr.Data[/eluser]
Hello!
I dont like the result_array function of the database class. If I just run a query with a select part, the result is the following:
Code:
array
  0 =>
    array
      'year' => string '2008/2009' (length=9)
  1 =>
    array
      'year' => string '2007/2008' (length=9)
  2 =>
    array
      'year' => string '2010/2011' (length=9)
  3 =>
    array
      'year' => null
  4 =>
    array
      'year' => string '2009/2010' (length=9)
So now I have to do this:
Code:
$this->db->select('year');
$tmp = $this->db->get('groups');
$years = array();
foreach ($tmp as $item) {
    $years[] = $item['year'];
}
Isn't there a simpler way to do this? It would be best if result_array returned a numeric one-dimensional array. The problem is, that I cannot run a foreach loop with the array above because it is two dimensional.




Theme © iAndrew 2016 - Forum software by © MyBB