user3932764
user3932764

Reputation: 15

PHP news system with mysql?

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

Answers (2)

Basit
Basit

Reputation: 1840

You're echoing 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

Quentin
Quentin

Reputation: 943108

Put the echo statement inside the while loop.

Upvotes: 1

Related Questions