Php Display Mysql Table - Php

How to display mysql table using php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

The following php code can be used to display mysql table. Here, "Select" option is used to select the data from mysql table.

<?php $link = mysql_connect("localhost", "root", ""); $dbc=mysql_select_db('testdb',$link); $query = "SELECT * FROM usertable"; $result = mysql_query($query) or die('Error querying database'); $count=mysql_num_rows($result); ?> <form name="form1" method="post" action=""> <table border="1" align='center'> <caption><b>Display Mysql Table</b></caption> <tr> <th>ID</th><th>Name</th><th>City</th> </tr> <?php while ($row=mysql_fetch_array($result)) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['city']; ?></td> </tr> <?php } ?>

Tags


Ask Questions

Ask Question