Page 1 of 1

Putting field names in a CSV

Posted: Mon Jan 18, 2010 1:44 pm
by michaelk46
I have been able to export the data from a MySQL database table and place it into A csv file, but I am not sure how to get the table field names to put them into the file first. The only command I have found that specifically did that is deprecated. Can someone give me a nudge in the right direction on which command I can use or maybe some resources that someone found to fix this issue.

Thanks All

Re: Putting field names in a CSV

Posted: Mon Jan 18, 2010 2:17 pm
by AbraCadaver
There are examples on the mysql_list_fields() page that use a "SHOW COLUMNS FROM sometable" appraoch, but I would try this in your loop:

Code: Select all

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    if(!isset($field_names)) {
        $field_names = array_keys($row);
    }
    // whatever you do with the $row array
}

Re: Putting field names in a CSV

Posted: Mon Jan 18, 2010 2:37 pm
by michaelk46
Thanks dude...