Reputation: 15
I am trying to make a news sytem in php. The DB structure looks like this
"title" "author" "content"
And the PHP script looks like this
<?php
include ('config2.php');
$result = mysql_query("select * from news");
while($row = mysql_fetch_array($result)) {
$title = $row['title'];
$author = $row['author'];
$content = $row['content'];
}
echo"<div class=\"post\">
<h2 class=\"title\"><font color=\'#1e1e1e\' href=\"#\">$title</font></h2>
<p class=\"meta\">Today <a href=\"#\">$author</a></p>
<p>$content</p>
</ul>
</div>"
?>
What I want to do is : Each time I insert a new row in my db, I want the new to be displayed on the page, and right now when I add a new row it just edit the previous new. Any idea?
Upvotes: 0
Views: 391
Reputation: 1840
You're echo
ing outside the while
loop. Modify it to the following:
while($row = mysql_fetch_array($result)) {
$title = $row['title'];
$author = $row['author'];
$content = $row['content'];
echo"<div class=\"post\">
<h2 class=\"title\"><font color=\'#1e1e1e\' href=\"#\">$title</font></h2>
<p class=\"meta\">Today <a href=\"#\">$author</a></p>
<p>$content</p>
</ul>
</div>";
}
Upvotes: 1