Actually, I just removed the \r\n and it puts them all out on the same line, comma deliminated:
$link = mysql_connect('localhost', 'user', 'pass');
$fields = mysql_list_fields("db1", "table", $link);
$columns = mysql_num_fields($fields);
$csv = fopen("/path/to/file.csv", "w");
for ($i = 0; $i < $columns; $i++) {
$fieldnames = mysql_field_name($fields, $i);
fwrite($csv,"$fieldnames,");
}
fclose($csv);
I have the field names now listed as such:
filedname1,fieldname2,fieldname3
As it stands, I'm now working on a break after the field names, and having the rest of my data listed in a separate section.
Basically it's going to look similar to this:
fieldname1,fieldname2,fieldname3
data1,data2,data3
data2.1,data2.2,data2.3
The only problem is, now I have the first line of data immediately after the fieldnames:
fieldname1,fieldname2,fieldname3,data1,data2,data3
data2.1,data2.2,data2.3
data3.1,data3.2,data3.3
make sense?
I've added a \n to the beginning of my second write to the file, but this only double spaced the data results:
fieldname1,fieldname2,fieldname3
data1,data2,data3
data2.1,data2.2,data2.3
data3.1,data3.2,data3.3
sooooo... I'm trying to figure out a way to have one single break after the field names, and then the data starts.
I know this seems confusing, and I really do appreciate all your help with this, even though I know it seems simple to most, I appear to be struggling.