Hi I want to output a table with headings
the following code prints only the data
I have tried outputting the $col_name in the second while statement but I get the heading with each line of date
I have played around with it but can't get the rsult I want
whis would be something like
ID Name Title
1 John Mr
2 Jim Dr
3 Jane Mrs
I either get
1 John Mr
2 Jim Dr
3 Jane Mrs
or
ID Name Title
1 John Mr
ID Name Title
2 Jim Dr
ID Name Title
3 Jane Mrs
or
ID Name Title
ID Name Title
ID Name Title
or nothing at all
code >>>
<?php
$link = mysql_connect("mysql_host", "mysql_login", "mysql_password")
or die ("Could not connect");
print ("Connected successfully");
mysql_select_db ("my_database")
or die ("Could not select database");
$query = "SELECT * FROM my_table";
$result = mysql_query ($query)
or die ("Query failed");
// printing HTML result
print "<table>\n";
while ($line = mysql_fetch_array($result)) {
print "\t<tr>\n";
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
thanks
the following code prints only the data
I have tried outputting the $col_name in the second while statement but I get the heading with each line of date
I have played around with it but can't get the rsult I want
whis would be something like
ID Name Title
1 John Mr
2 Jim Dr
3 Jane Mrs
I either get
1 John Mr
2 Jim Dr
3 Jane Mrs
or
ID Name Title
1 John Mr
ID Name Title
2 Jim Dr
ID Name Title
3 Jane Mrs
or
ID Name Title
ID Name Title
ID Name Title
or nothing at all
code >>>
<?php
$link = mysql_connect("mysql_host", "mysql_login", "mysql_password")
or die ("Could not connect");
print ("Connected successfully");
mysql_select_db ("my_database")
or die ("Could not select database");
$query = "SELECT * FROM my_table";
$result = mysql_query ($query)
or die ("Query failed");
// printing HTML result
print "<table>\n";
while ($line = mysql_fetch_array($result)) {
print "\t<tr>\n";
while(list($col_name, $col_value) = each($line)) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
thanks