How come this works?
I have a MySQL table with the following fields:
name, address, phone
Then I do this to retrieve the values:
if (condition==true ) {
$query="SELECT name,address,phone FROM table . mysql_error();
} else {
$query="SELECT name,address,phone FROM other_table . mysql_error();
}
$result=mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
extract($row);
}
And then I can output the values from the db if I use the same variable names as the database fields:
echo $name;
echo $address;
echo $phone;
Is it suppose to work like this? I thought I had to use $field = $myrow["field"] in the while loop to retrieve the values from the db and assign them to variables (which is a lot more code when you retrieve 10 or 15 values). But it seems like extract($row) is automatically creating variables that are named the same as my db fields and assigning the values of those fields to the contents of the variables.
Just looking for confimation that this is the case or if I may be overlooking something else. Thanks.