<?php
/*array*/ function get_field_names($table) {
$sql = 'SELECT * FROM TABLENAME';
$result = mysql_query($sql);
$retval = array();
for ($i = 0; $i < mysql_num_fields($result); $i++) {
$fname = mysql_field_name($result, $i);
$fvalue = mysql_result($result,0,$i);
$retval[$fname] = $fvalue;
} //end for
return $retval;
} //end get_field_names
?>
This will return an array with the fields as the keys and the values as the values but it could be done a lot more easily like this:
<?php
/*array*/ function get_field_names($table) {
$sql = 'SELECT * FROM TABLENAME';
$result = mysql_query($sql);
return mysql_fetch_assoc($result);
} //end get_field_names
?>
Note that these two functions are equivocal.
Then you can get at the field names like this:
<?php
$fields_ary = get_field_names('my_table');
$field_names = array_keys($fields_ary);
?>
and you can turn them into globals like this:
<?php
$fields_ary = get_field_names('my_table');
foreach(array_keys($fields_ary) as $key)
$$key = $fields_ary[$key];
?>
However I usually just work with the associative array, I find that once you're used to doing it that way it is easier and more readable as you can easily see where the stuff is comeing from.