Forum Moderators: coopster
with an error at the link
// Do stuff to get your actual data, store in scalar, note the "if" below
$tablecontent=null;
$query = "select * from table order by $sort $direction";
$result = mysql_query($query) or die("Cannot execute query: " . mysql_error());
while ($row=mysql_fetch_array($result)) {
$tablecontent .= '<tr>';
// Skip the ID field - or maybe not, if you need it
for ($i=1;$i<=$count;$i++) {
// Remembering mysql_fetch_array returns both an indexed and
// an associative array
$tablecontent .= '<td>' . $row[$i] . '</td>';
}
$tablecontent .= '</tr>';
}
if ($tablecontent) {
echo '<table><tr>';
for ($i=1;$i<=$count;$i++) {
$tablecontent .= '<th><a href="script.php?sort=' . $fieldNames[$i] . '">' . $fieldNames[$i] . '</th>';
}
echo "</tr>$tablecontent </table>";
}
else { echo "<p>There are no results to display.</p>"; }
function get_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) { error("Could not get table names: " . mysql_error()); }
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
$fields[$counter]=$row[0];
$counter++;
}
return $fields;
}