| Gregor Favre 2004-06-25, 6:47 pm |
| Hi Martijn
> Is there a fancy way to retrieve the contents of a table plus the names of
> the Columns for use in Excel? In often choose to download its contents in
> "CSV for Ms Excel data"-format from MYSQL, and opening this file yields
the
> entire table in Excel. The data comes, unfortunately, without the column
> names.
(I assume you are talking about some existing PHP application and not about
mysqldump)
To get the fields, do something according to the phpmanual code below:
$fields = mysql_list_fields("database1", "table1", $link);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++) {
echo mysql_field_name($fields, $i) . "\n";
}
Now that you have these fields, you may write them into the top of your
excel sheet, for instance by using the PEAR package
Spreadsheet_Excel_Writer.
Greetings, Greg
|