If you are using ODBC to connect to your database, you can use the built-in odbc_field_name function to return a list of column names. Something like this should do the trick, although you may prefer to assign the results to an array rather than output them as I have done here:
$Number_of_Columns = odbc_num_fields($Database_Handle);
for ($Index = 1; $Index <= $Number_of_Columns; $Index++) {
$Something = odbc_field_name($Database_Handle,$Index);
echo "Column # $Index: $Something\n";
}
By the way, just as a security precaution, you should probably be very careful about who you allow to see the table names in your database, variable names, etc.