如何将最近的帖子从数据库显示到php主页?

I want to display post details ( title, description, username ) on my home page within a div tag in a proper format like all websites have. The problem I'm facing is that all the data from database are getting displayed as a plain text, one below the other. I am new to php, so please guide me to achieve the result.

Here is my code.

I want to display in this tag:

<div id='display'>
  <h3 class='name'></h3>
  <h1 class='title'></h1>
  <p class='desc'></p>
  <p class='cat'></p>
  <p class='sub_cat'></p> 
</div>

And my php code is:

<?php
  $row="";

  $link = mysql_connect("localhost","username","password");
  mysql_select_db("database");
  $query = "SELECT * from posts ORDER by post_id DESC limit 0,5";
  $result = mysql_query($query);
  $result = mysql_query($query) or die("Query to get blah failed with error:".mysql_error());

  while($row = mysql_fetch_array($result)) { 
    echo "<div id='display'>";
    echo "<h3 class='name'>".$row['username']."</h3>";
    echo "<h1 class='title' >".$row['post_title']."</h1>";
    echo "<p class='cat'>".$row['cat']."</p>";
    echo "<p class='sub_cat'>".$row['sub_cat']."</p>";
    echo "<p class='desc'>".$row['post_desc']."</p>";
    echo "</div>";
  } 

  mysql_close($link);
?>

I think what you are missing is some CSS. In HTML, DIV-Containers are displayed as block elements. So without any configuration, they are displayed one below the other. To get them next to each other, just add some CSS to your page:

<div id='display'>
  <h3 class='name'></h3>
  <h1 class='title' ></h1>
  <p class='desc'></p>
  <p class='cat'></p>
  <p class='sub_cat'></p> 
</div>
<div class="clear"></div>


<style type="text/css">
.name, .title, .desc, .cat, .sub_cat {
    float:left;
}

.clear {
    clear:both;
}
</style>