I have a function that retrieves news from my database to output it. I use a small template system that works pretty well and I'm having problems displaying the news in it. Here's my news function:
function displayNews($all = 0) {
global $db, $max_items, $index;
/* query for news items */
if ($all == 0) {
$query = ("SELECT title,author,topic,content,DATE_FORMAT(date, '%Y-%m-%d') as date FROM news ORDER BY date DESC");
} else {
$query = ("SELECT title,author,topic,content,DATE_FORMAT(date, '%Y-%m-%d') as date FROM news ORDER BY date DESC");
}
$result = mysql_query($query)or die (mysql_error());
while ($row = mysql_fetch_array($result)) {
$date = $row['date'];
$author = $row['author'];
$topic = $row['topic'];
$title = htmlentities ($row['title']);
$news = nl2br (strip_tags ($row['content']));
$display .= "<h1>$title</h1>";
$display .= "<h2>$date</h2>";
$display .= "<h2>By: $author</h2>";
$display .= "<h3>Topic: $topic</h3>";
$display .= "$news";
$display .= "<h4></h4>";
$index->replace_tags(array(
"errormsg" => "$msg",
"news" => "$display",
));
}
}
displayNews();
$index->replace_tags(array(
"errormsg" => "$msg",
"news" => "$display",
));
Replaces {news} in the template file with $display. The problem is, it only displays the first row in the table. If I echo every line instead of $display and just comment out the whole $index->replace_tags block, it displays each row as it should it's just not in the template how I want. How can I get it to output every row to my template?