RE: [PHP] save html created by loop in variable

From: Date: Thu, 18 Apr 2002 08:46:34 +0000
Subject: RE: [PHP] save html created by loop in variable
Groups: php.general 
Request: Send a blank email to php-general+get-93497@lists.php.net to get a copy of this message
How about something like ... $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"]}"); } } Please treat this as pseudo code, but you get the idea. Arrays of arrays can be really powerful for stuff like this. Tim Ward Internet Chess www.chessish.com <http://www.chessish.com> ---------- From: Jason Dulberg [SMTP:jdulberg@nas.net] Sent: 18 April 2002 05:27 To: php-general@lists.php.net Subject: RE: [PHP] save html created by loop in variable Thanks for your reply... I just tried it with ob_start(); and I think I'm almost on the right track. Just one small issue. Since the records are in a while loop, the results are printed line by line as expected. However, I need to print something obtained from the sql query just once then the rest to loop. //a.agentname displays only once and h.title/h.address will be in a list SELECT h.title, h.address, a.agentname FROM homes h, agents a WHERE h.owner=a.id AND a.id=$aid Basically what I'm after is displaying something like: Agent: Fred nice house, 123 street ugly house, 643 road Thanks again for your help on this. Jason > -----Original Message----- > From: Miguel Cruz [mailto:mnc@stoic.net] > Sent: April 17, 2002 8:28 PM > To: Jason Dulberg > Cc: php-general@lists.php.net > Subject: Re: [PHP] save html created by loop in variable > > > On Wed, 17 Apr 2002, Jason Dulberg wrote: > > I have a WHILE loop that I am interested in storing the html that is > > generated based on its results to a variable. This variable > would then be > > echoed later on. > > Check in the manual under Output Buffering. > > miguel > >

« previous php.general (#93497) next »