OK, putting together a simple table based on the output from a sql query. mysql_num_fields() returns 9 so I know I'm getting ONE row back. mysql_field_name($result, $i) returns the column name.
When I try to output the table row(s), I get nothing... nada... zip... I must be missing something! (tired eye/brain syndrome?)
Here's the code:
the output can be found here: http://hoatime.com/buildgrid.php
<?php
include "inc/sqlinc.php";
$table = "hoa_board";
// get all records
$query = "SELECT * FROM $table WHERE 1";
// query the database
$result = mysql_query($query) or die(mysql_error());
//see how many records/rows we got back
$totalField = mysql_num_fields($result);
//print table/grid headers
echo "<html><head></head><body>\n";
echo "<center>\n";
echo "<br>Tot Fields: $totalField<br>\n";
echo "<table>\n";
echo "<tr>\n";
echo "<th>Add</th>\n";
echo "<th>Edit</th>\n";
echo "<th>Delete</th>\n";
for($i = 0; $i < $totalField; $i++)
{
echo "<th>\n";
echo (mysql_field_name($result, $i));
echo "</th>\n";
}
echo "</tr>\n";
// Rewind the pointer on the result handle
mysql_data_seek ($result, 0);
// print out the data rows
while($row = mysql_fetch_assoc($result))
{
// start a new row
echo "<tr>\n";
// send out the icons with links so the user can add/edit/delete records
// url is formatted as: http://www.foo.com/form_name.php?action=type&rec_id=123
echo " <td><a href='hoa_board.php?action=add&$row[$i]'><img src='images/addicon.gif'></a></td>\n";
echo " <td><a href='hoa_board.php?action=edit&$row[$i]'><img src='images/editicon.gif'></a></td>\n";
echo " <td><a href='hoa_board.php?action=del&$row[$i]'><img src='images/deleteicon.gif'></a></td>\n";
// now output the record for this row
for($i = 0; $i < $totalField; $i++)
{
echo " <td>$row[$i]</td>\n";
}
// end the record for this row
echo "</tr>\n";
}
// end the table
echo "</table>\n";
echo "</center>\n";
echo "</body></html>\n";
?>