On Mon, 06 Feb 2006 07:14:21 -0600
Pastor Steve <[EMAIL PROTECTED]> wrote:
>
> Greetings,
> 
> I am attempting to put the results of a ³while² loop into a variable.
> 
> 
> Example:
> 
> $result = mysql_query(³SELECT filename, page_title FROM table²);
> while ($row = mysql_fetch_assoc($result))
> 
>         {
> 
>                 $var = ³<a
> href=\²$htmldir{$row[Œfilename¹]}\²>{$row[Œpage_title¹]}</a><br />²;
>                     echo ³$var²;
> 
>         }
> 
> I would like for the the entire ³while² statement result to be in a
> variable for use outside of the statement. Is that possible?

Try this:

$result = mysql_query(³SELECT filename, page_title FROM table²);
$var = "";      // Make sure $var is empty.
while ($row = mysql_fetch_assoc($result))

        {

                $var .= ³<a     // Note the period before the equals!
href=\²$htmldir{$row[Œfilename¹]}\²>{$row[Œpage_title¹]}</a><br />²;
 
        }

echo ³$var²;    // Echo $var to the screen.

The .= instead of just plain = will append the result to $var instead
of over-writing it, so by the end of the while loop $var will contain
the whole thing. Then, just echo $var once at the end of the while loop.

Note - script not tested...

Regards,
Ozz.

Attachment: pgpeWNDoxAn1p.pgp
Description: PGP signature

Reply via email to