Page 1 of 1

build a variable with all HTML

Posted: Sun Dec 02, 2007 4:38 pm
by GeXus
I'm looping through a data set, just like any other time, however instead of writing out the results on the page such as

Code: Select all

while($row = mysql_fetch_array($query)){

echo "<div>";
echo $row['name'];
echo "</div>";

}
I want to put all of what would be written out into one single variable... I could create a page that writes everything out, then just use that page to do a file_get_contents and grab html, but I'm not sure if thats the best way....

Any thoughts?

Thanks!

Posted: Sun Dec 02, 2007 4:47 pm
by vigge89

Code: Select all

$output = '';

while($row = mysql_fetch_array($query)){
    $output .= "<div>";
    $output .= $row['name'];
    $output .= "</div>";
}

echo $output; // echoes everything

Posted: Sun Dec 02, 2007 11:16 pm
by s.dot
vigge89 is correct
it's an assignment operator, which you can read about here: http://us.php.net/manual/en/language.op ... gnment.php

Posted: Mon Dec 03, 2007 7:43 am
by staar2
i would use for outputting html this style :

Code: Select all

$herdoc = <<<HTML
Here you can add php and also use" ' $var 
HTML;