For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > June 2004 > Re: Retrieve column names with MYSQL/MSEXCEL output?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Retrieve column names with MYSQL/MSEXCEL output?
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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com