I really need your help. I am trying to echo a table from my database but it first of all comes with my table names from the database which I don't want and also the css is weird. I would like my table to have a different heading in each column then the data displayed below the corresponding column header in a uniform manna.
the php code is here
<div id="content-1">
<div>
<?php
$table = 'std_details';
// sending query for table
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
die ("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>All Students</h1>";
echo "<table border='2' class='gridtable'><tr>";
// printing table headers
for ($i=0; $i < $fields_num; $i++) {
$field = mysql_fetch_field($result);
echo "<td>{$field->name} </td>";
}
echo "</tr>
";
// printing table rows
while ($row = mysql_fetch_row($result)) {
echo "<tr>";
// $row is array.... foreach( .. ) puts every element
// of $row to $cell variable
foreach ($row as $cell) {
echo "<td> \t$cell</td>";
}
echo "</tr>
";
}
mysql_free_result($result)
?>
</div>
</div>
And the table css is
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
Thanks guys. I really need help!