build a variable with all HTML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

build a variable with all HTML

Post 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!
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Code: Select all

$output = '';

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

echo $output; // echoes everything
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
staar2
Forum Commoner
Posts: 83
Joined: Fri Apr 06, 2007 2:57 am

Post 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;
Post Reply