Friday, September 19, 2014

Display data in the table from database.

First create the database and name it fdb.
Then create table with 2 columns in the database and name it simp.
Insert data in the table.

Demo :)

Now php file :)

<?php
$dbserver="localhost";
$dbusername="root";
$dbpassword="";
$dbname="fdb";

$link=mysql_connect($dbserver,$dbusername,$dbpassword);
mysql_select_db($dbname,$link);

function displaytable($tablename,$link)
{
$query = "SELECT city FROM $tablename";
$res = mysql_query($query,$link);
$ccount = mysql_num_fields($res);

echo "<table border=1>";
echo ("<tr align=center>");
echo "<td><b>City List</b></td>";
echo "</tr>";

while($row=mysql_fetch_array($res))
{
echo ("<tr>");
for($col=0;$col<$ccount;$col++)
{
echo"<td> $row[$col]</td>\n";
echo"</tr>\n";
}
}
echo "</table>\n";
}
?>
<html>
<head>
<title>Display Table Data</title>
</head>
<body>
<h4>Table Data</h4>
<hr/>
<table>
<tr>
<td>
<?php
displaytable("simp",$link);
?>
</td>
</tr>
</table>
</body>
</html>

Output :)

No comments:

Post a Comment