Re: alternative to mysql_field_name()

From: Date: Wed, 22 Sep 2004 07:44:34 +0000
Subject: Re: alternative to mysql_field_name()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197526@lists.php.net to get a copy of this message
Luke wrote:
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";
}

« previous php.general (#197526) next »