Forum Moderators: coopster
while($row = mysql_fetch_array($result)){
echo "<td>";
echo $row['foo'];
echo "</td><td>";
echo $row['foofoo'];
echo "</td></tr>\n";
echo "<tr>\n";
}
echo "<td> </td><td> </td></tr>\n";
$output_rows=null;
while($row = mysql_fetch_array($result)){
//
$output_rows .= "\n<tr>\n";
for ($i=0;$i<$num_fields;$i++) { // array=zero based
// Don't leave empty TD's. IE hates them.
if (! $row[$i] or empty($row[$i])) { $row[$i] = ' '; }
$output_rows .= "<td>" . $row[$i] . "</td>\n";
}
$output_rows .= "<tr>\n";
}
if ($output_rows) {
$final = '
<table border="1">
<th>
';
for ($i=0;$i<$num_fields;$i++) {
$final .= "<td>" . $field_list[$i] . "</td>";
}
$final .= "
</th>
$output_rows
</table>
";
}
else { $final = "<p>No records were found.</p>"; }
echo $final;
// Returns a list array of table field names.
function field_names($table) {
if (! isset($table)) { die("No table in field names"); }
$fields = Array ();
$counter=0;
$result = mysql_query("show columns from $table");
if (!$result) { die("Could not get table names: " . mysql_error()); }
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
$fields[$counter]=$row[0];
$counter++;
}
return $fields;
}
$field_list = field_names($table);
$num_fields = count($field_list);
echo $num_fields;
while($row = mysql_fetch_array($result)){
//
$output_rows .= "\n<tr>\n";
for ($i=0;$i<$num_fields;$i++) { // array=zero based
// Don't leave empty TD's. IE hates them.
if (! $row[$i] or empty($row[$i])) { $row[$i] = ' '; }
$output_rows .= "<td>" . $row[$i] . "</td>\n";
}
$output_rows .= "<tr>\n";
}
if ($output_rows) {
$final = '
<table border="1">
<th>
';
for ($i=0;$i<$num_fields;$i++) {
$final .= "<td>" . $field_list[$i] . "</td>";
}
$final .= "
</th>
$output_rows
</table>
";
}
else { $final = "<p>No records were found.</p>"; }
echo $final;
<th><td>name-a</td><td>name-b</td></th>