Friday, 16 September 2016

How To Display Table Records in PHP and Mysql:Displaying Table records in HTML Table

Displaying Table records in HTML table is much easier,first create table with the name of employee as described below,then create columns id,emp_name,designation,city. Excute select query from that table. Make a array to receive that data,after create HTML table then display those array values in the <td> values. 

Viewing records from table:

View the table records:

to view the table contents create table as follws:
Table name:employee.
columns:id,emp_name,designation,city.

here the codes...

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
$con=mysql_connect('localhost','root','') or die("could not connect");
mysql_select_db('mini_project') or die("database could not connected");
$sql="select id,emp_name,designation,city from employee";
$result=mysql_query($sql);
if(! $result) {
      die('Could not get data: ' . mysql_error());
   }
?>
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tR>
    <TD width="30%">NAME</TD>
    <TD width="40%">DESIGNATION</TD>
    <TD width="30%">SALARY</TD>
    <TD width="30%">action</TD>
</tr>
<?php
$i=1;
while($rows=mysql_fetch_array($result))
{
  ?>


    <TD width="30%"><?php echo $rows['emp_name']; ?></TD>
    <TD width="40%"><?php echo $rows['designation']; ?></TD>
    <TD width="30%"><?php echo $rows['city']; ?></TD>
    </tr>
<?php
}
?>
</table>
<?php
mysql_close($con);
?>
</body>
</html>

No comments:

Post a Comment