Posted by Arjun on Thursday 31st May 2012

Displaying MySQL Table records in unordered list format Using PHP?

Table records unordered list

This post is about data retrieving from MySQL database table using PHP. The bellow PHP script will give you Unordered list format output.

Before doing any operations on database server, you must open connection to the server if your not filmier with database connection click here

<?php 
$db = mysql_connect('localhost','root','');
mysql_select_db('test_db',$db);
$query = mysql_query("SELECT * FROM test_table");
while($row = mysql_fetch_object($query) ) {
  $data[] = $row;
}
?>
 
<ul>
  <?php foreach($data as $items) {  ?>
  <li><a href="<?php  echo $items->item_url; ?>" title="<?php echo  $items->item_name; ?>"><?php echo  $items->item_name; ?></a> </li>
  <?php } ?>
</ul>

Using PHP you can fetch data from database in several ways, here is another post which covered another method, visit it for more info PHP Function to get data from MySQL Database?