I am trying to output multiple arrays into a csv file with pre-set headers. so far i can only manage to output 2 of the exact same results into the csv (sql result 0). I believe i have my "for" statements in a muddle somehow and believe this is probably very easy to fix but for the life of me cannot see it. Does anyone have any ideas at all, or any better way to do this csv output?
// output headers so that the file is downloaded rather than displayed
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="SageImport.csv"');
// do not cache the file
header('Pragma: no-cache');
header('Expires: 0');
// create a file pointer connected to the output stream
$file = fopen('php://output', 'w');
// send the column headers
fputcsv($file, array('Reference', 'Company Name', 'Currency', 'Credit Limit', 'Main Address Type', 'Main Address Line 1', 'Main Address Line 2', 'Main Address Town', 'Main Address County', 'Main Address Post Code', 'Main Address Country', 'Main Contact Name', 'Main Contact Phone', 'Main Contact Type', 'Main Contact Mobile', 'Main Contact Email', 'Main Contact Fax', 'Address 2 Type', 'Address 2 Line 1', 'Address 2 Line 2', 'Address 2 Town', 'Address 2 County', 'Address 2 Post Code', 'Address 2 Country', 'VAT Number', 'Ledger Account', 'Payment Terms', 'Notes', 'Bank Account Name', 'Bank Account Sort Code', 'Bank Account Number', 'Bank Account IBAN', 'Bank Account BIC'
));
$query = "SELECT * FROM clients WHERE sageexport='0'";
$result = mysql_query($query) or die("Error: ".mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$info[] = $row;}
for ($i = 0; $i < count($info); $i++) {
if ($info[$i][10] = "yes") {$agreed = 'Agreement';}
$data = array($info[$i][1], $info[$i][2], 'GBP', '', '', $info[$i][3], '', $info[$i][4], $info[$i][5], $info[$i][6], 'GB', '', $info[$i][8], '', '', $info[$i][7], '', '', '', '', '', '', '', '', '', '10001', '10', $agreed, '', '', '', '', '');
}
$agreed = "";
// output each row of the data
for ($i = 0; $i < count($info); $i++) {
foreach (array($data) as $row2){fputcsv($file, $row2);}
}
exit();