How to fetch record from database in PHP

First we have to create database in phpmyadmin and then we have to create a table.
For example :
Database :          yourdbname
Table      :           user

roll                            name                     email

1                               arvind           

2                               ajay              

3                               alok              

Here is the following code in php to fetch data from database and show it on output-


$con= mysql_connect((“hostname”, “username”, “password”) or die (mysql_error()));
$db= mysql_select_db(“yourdbname”, $con);

$sql= “SELECT * FROM user WHERE 1”;
$qry= mysql_query( $sql );



<td>Roll-No</td> <td> studentname </td> <td> Email</td>

while  ( $rs = mysql_fetch_array($qry))
<td> <?php echo $rs[roll];</td> <td> <?php echo $rs[name]; ?></td> <td>  <?php echo $rs[email]; </td>

Leave a Reply

Your email address will not be published. Required fields are marked *