<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="blog"; // Database name
$tbl_name="posts"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Retrieve data from database
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<?php
// Start looping rows in mysql database.
$row=mysql_fetch_array($result);
while($row){
?>
<tr>
<td width="10%"><?= $row['id']; ?></td>
<td width="30%"><?= $row['title']; ?></td>
<td width="30%"><?= $row['body']; ?></td>
<td width="30%"><?= $row['published']; ?></td>
</tr>
<?php
$row=mysql_fetch_array($result);
// close while loop
}
?>
</table>
<?php
// close MySQL connection
mysql_close();
?>