hey m making a projec in one of its page i want to get the data from the table and display it on screen in the form of table. allthough the data appears but how can i display the headings.

$num=mysql_num_rows($result);
 
 print "<table width=600 border=1>\n";
 
while ($get_info = mysql_fetch_row($result))
{
print "<tr>\n";

foreach ($get_info as $field)

print "\t<td>$field</td>\n";

print "</tr>\n";
}

print "</table>\n";
mysql_close($con);
?>

Recommended Answers

All 4 Replies

Add them manually before the while loop:

print '<tr><th>Your field name here</th></tr>';

each time when i tries it gives this error

syntax error, unexpected '<' in

this is my whole code

<html>
<head>

<title>Display Records</title>

</head>

<body>

<?php 


 
 $con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
 
 $query= "SELECT * FROM employee";
 
 $result=mysql_query($query);
 
 $num=mysql_num_rows($result);
 
 print "<table width=600 border=1>\n";
 
<tr><th>id</th>
<th>name</th>
<th>password</th>
<th>rank</th>
<th>department</th>
<th>nic</th>

<th>numbr</th>
<th>adress</th>

<th>s</th></tr>
while ($get_info = mysql_fetch_row($result))
{
print "<tr>\n";

foreach ($get_info as $field)

print "\t<td>$field</td>\n";

print "</tr>\n";
}

print "</table>\n";
mysql_close($con);
?>
 
 </body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.