0

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);
?>
2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by pritaeas
0

Add them manually before the while loop:

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

Edited by pritaeas: n/a

0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.