I want is 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 im 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 :
And my php code is :
I need the title to be a link . Thanks in advance .
I want to display in this tag :
Code:
<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>
Code:
<?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); ?>
Comment