fputcsv - insert columns under each other
<p>Sorry for the title, but i didn´t know how to explain better. I´m exporting to a csv file two tables, but the final layout isn´t what i´m expecting, and i really don´t know how to perfom this, what i have right know is:</p>

<pre><code>$sql = "SELECT a.number, a.location,a.confirmed etc etc FROM campain UNION ALL SELECT workerNumber, workerName, socialSecurity,day1nh,day1eh,day2nh,day2eh etc etc FROM timesheet";

$qry = $pdo-&gt;prepare($sql);
$qry-&gt;execute();
$filename = "exportcsv/file".time().".csv";
$data = fopen($filename, 'w');
$row = $qry-&gt;fetch(PDO::FETCH_ASSOC);

if ($row) 
{
    fputcsv($data,array_keys($row), $delimiter = ';');

    while ($row) 
    {
        $array = array_map("utf8_decode", array_values($row));
        fputcsv($data,$array, $delimiter = ';');
        $row = $qry-&gt;fetch(PDO::FETCH_ASSOC);
    }
 fclose($data); 
}
</code></pre>

<p>This exports a nice csv with all the columns well separated but it shows me everything side-by-side, and as you can see i have day1nh and day1eh etc and instead of this on the output:</p>

<pre><code>workerNumber workerName socialSecurity day1nh day1eh
</code></pre>

<p>i want this:</p>

<pre><code>workerNumber workerName socialSecurity day1nh day2nh etc

                                       day1eh day2eh etc
</code></pre>