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

One thought on “Connect PHP with MySQL and display data rows into HTML table

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s