tags:

views:

27

answers:

1

I was wondering. I always do fetch and then create variables when I do loop. Is there a way to do this more efficient? Like as in automatically?

Maybe something like convert_to_variable("name","description","etc") and it'll automatically set variables for me without having to do each manually? Or maybe a single command like convert_to_variable($rows) and it'll do the rest for me.

Here is what I am doing now.

$sql = "SELECT * from projects";
$rows = $db->fetch_all_array($sql);
 foreach($rows as $row) {
  $name = $row['name'];
  $description = $row['description'];
}

Something easier would be

$sql = "SELECT * from projects";
$rows = $db->fetch_all_array($sql);
 foreach($rows as $row) {
  convert_to_variable($row);
  echo $name, $description;
}
+5  A: 

extract can do that for you.

Emil Vikström
brilliant. thanks
Scott