freecrm
New Member
- Messages
- 629
- Reaction score
- 0
- Points
- 0
Hi all
I'm trying to code a data export function but having one simple problem.
mysql_connect and select db has been done in seperate connection file
First off, I've created a recordset called $RScontacts.
It works great, BUT - each new row isn't being defined in the csv file so I get one long row with all table row data. - no new lines.
Am I going about this the wrong way?
I'm trying to code a data export function but having one simple problem.
mysql_connect and select db has been done in seperate connection file
First off, I've created a recordset called $RScontacts.
PHP:
$out = '';
// Get all fields names from table.
$fields = mysql_list_fields($database_freecrm,CONTACTS);
// Count the table fields and put the value into $columns.
$columns = mysql_num_fields($fields);
// Put the name of all fields to $out.
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($fields, $i);
$out .= '"'.$l.'",';
}
$out .="n";
// Add all values in the table to $out.
while ($l = mysql_fetch_array($RScontacts)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",';
}
$out .="n";
}
// Open file export.csv.
$f = fopen ('export.csv','w');
// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="Contact_Export.csv"');
readfile('export.csv');
It works great, BUT - each new row isn't being defined in the csv file so I get one long row with all table row data. - no new lines.
Am I going about this the wrong way?