itxtme
08-19-2012, 12:16 AM
I am trying to output each row as an array to then export a CSV. I have the code working however it is outputting two of each column value. I even know why it is outputting two, because the array created is listing the value as both indexed and numbered arrays. I dont know why it is doing this!
// Get profiles that were selected
$result_2 = mysql_query("SELECT {$query_ready} FROM all_child LEFT JOIN {$sql_instance}child ON {$sql_instance}child.{$sql_instance}child_id = all_child.child_id") or die(mysql_error());
while($row = mysql_fetch_array($result_2)){
$loop[] = $row;
}
foreach( $loop as $row )
{
fputcsv($outstream, $row, ',', '"');
}
fclose($outstream); ?>
With a print_r I can see the problem,
Array ( [0] => Array ( [0] => Array ( [0] => 1000001 [account_id] => 1000001 [1] => 10000007 [child_id] => 10000007
As you can see account_id is both [0] and [account_id] which is outputting two account ID values (and every other value) in my CSV file! Any help much appreciated
// Get profiles that were selected
$result_2 = mysql_query("SELECT {$query_ready} FROM all_child LEFT JOIN {$sql_instance}child ON {$sql_instance}child.{$sql_instance}child_id = all_child.child_id") or die(mysql_error());
while($row = mysql_fetch_array($result_2)){
$loop[] = $row;
}
foreach( $loop as $row )
{
fputcsv($outstream, $row, ',', '"');
}
fclose($outstream); ?>
With a print_r I can see the problem,
Array ( [0] => Array ( [0] => Array ( [0] => 1000001 [account_id] => 1000001 [1] => 10000007 [child_id] => 10000007
As you can see account_id is both [0] and [account_id] which is outputting two account ID values (and every other value) in my CSV file! Any help much appreciated