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:[EMAIL PROTECTED]]
Sent: 18 April 2002 05:27
To: [EMAIL PROTECTED]
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:[EMAIL PROTECTED]]
> Sent: April 17, 2002 8:28 PM
> To: Jason Dulberg
> Cc: [EMAIL PROTECTED]
> 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
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php