Save results created by loop into a variable.
Posted: Wed Jan 07, 2009 10:12 am
I found this sample code a couple of places. I'm having a hard time seeing where the results are applied to a variable. All I get is echoed/printed results. Is there a $var in this code that holds the values that I'm seeing printed after running in a browser?
Code: Select all
$agents = array();
If ($result = mysql_query("SELECT h.title, h.address, a.agentname
FROM homes h, agents a WHERE
h.owner=a.id AND a.id=$aid"))
{ while ($array = mysql_fetch_array($result))
{ $agents[$array["agentname"]][] = $array;
}
}
foreach($agents as $agent=>$addresses)
{ echo("$agent<br>");
foreach($addresses as $address)
{ echo("{$address["title"]}, {$address["address"]}");
}
}