Connect PHP with MySQL and display data rows into HTML table

MySQL Database having table name “emp” has records as below,

mysqldb_emp

Below is the source code to connect PHP with MySQL:

<!DOCTYPE html>
<html>
<?php
mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“Employeedb”) or die(mysql_error());
$data = mysql_query(“Select * from emp”)
or die(mysql_error());

while($row = mysql_fetch_assoc($data))
{

echo “<table style=’border: 1px solid black; width:40%’>
<tr>
<td style=’border: 1px solid black; width:20%’>”.$row[“EmpID”]
.”</td>
<td style=’border: 1px solid black;’>”.$row[“EmpName”]
.”</td>
</tr>
</table>”;

}
?>
</html>

Below is output:

phpemppage

Advertisements