hi there,
i am currently using the following code to loop through the results of a sql query and extract the field names ($export contains the query results from the database). the script goes on to place the results in an excel file.
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
however, i'd like to add more meaningful names as the field name headings in the excel file. can anyone suggest how i can write a list of tab separated headings into $header?
$header_texts = array('column1' => 'Column One', 'column2' => 'Column Two');
for ($i = 0; $i < $fields; $i++) { $header .= $header_texts[mysql_field_name($export, $i)] . "\t"; }
Or you can use constants:
define('TEXT_HEADER_COLUMN1', 'Column One'); define('TEXT_HEADER_COLUMN2', 'Column Two');
for ($i = 0; $i < $fields; $i++) {
$header .= constant('TEXT_HEADER_' . strtoupper(mysql_field_name($export, $i))) . "\t";
}
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php