Click to See Complete Forum and Search --> : loop withing $var .= <<<EOA


knowj
12-28-2005, 10:54 AM
how would i go about making this sql/php script loop to show all results in the database? the loop isnt the problem with me its that im using an include and echoing on my index.php page so i cant echo each variable within the loop in the script

im just assigning everything to the variable $diary to be echoed on the index.php page



$query = 'SELECT * FROM diary ORDER BY diary_no DESC';
$result = mysql_query($query, $link);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$diary .= <<<DIARY
<!-- beginning of text left -->
<h1>Latest Diary Entry:</h1>
<p>{$row['diary_date']}</p>
<p>{$row['diary_text']}</p>
DIARY;


thanks in advance

chazzy
12-28-2005, 11:07 AM
Give this a try.

$query = 'SELECT * FROM diary ORDER BY diary_no DESC';
$result = mysql_query($query, $link);
$diary = "";//fake initialized
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$diary .= "<!-- beginning of text left -->\n<h1>Latest Diary Entry:</h1>\n<p>".$row['diary_date']."</p>\n<p>".$row['diary_text']."</p>";
}