Welcome Guest, Not a member yet? Register   Sign In
list-each, result_array
#1

[eluser]srisa[/eluser]
Hello,

I don't know if this is the expected behavior, but when i try to loop through the result set using the while list-each construct, script is timing out. Here is the sample code.
Code:
// construct 1: The script times out with this loop
$result = $this->db->query($sql);
$users = array();
while (list(, $r) = each($result->result_array()))
{
  $r['url'] = 'xyz.com/profile/'.$r['id'];
  $users[] = $r;
}

// construct 2:  This is okay
$result = $this->db->query($sql);
$users = array();
$x = $result->result_array();
while (list(, $r) = each($x))
{
  $r['url'] = 'xyz.com/profile/'.$r['id'];
  $users[] = $r;
}

// construct 3: And of course, the construct that i have used all along. this works.
$result = $this->db->query($sql);
$users = array();
foreach ($result->result_array() as $r)
{
  $r['url'] = 'xyz.com/profile/'.$r['id'];
  $users[] = $r;
}
Any ideas on why the first construct doesn't work?

Thank you.




Theme © iAndrew 2016 - Forum software by © MyBB