2

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:

$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->prepare($sql);
$qry->execute();
$filename = "exportcsv/file".time().".csv";
$data = fopen($filename, 'w');
$row = $qry->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->fetch(PDO::FETCH_ASSOC);
    }
 fclose($data); 
}

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:

workerNumber workerName socialSecurity day1nh day1eh

i want this:

workerNumber workerName socialSecurity day1nh day2nh etc

                                       day1eh day2eh etc
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50
Japa
  • 632
  • 7
  • 30
  • 1
    why are you assigning the delimiter in the call to`fputcsv($data,$array, $delimiter = ';');`? – Gordon Apr 22 '16 at 10:54
  • i thought that was the way of doing this, but you think this could be my problem? – Japa Apr 22 '16 at 10:55
  • Actually, if i delete that delimiter, it messes everything up. i´m lost!!! – Japa Apr 22 '16 at 10:57
  • No, I don't think this could be your problem. It will still pass ; to the call. I am just wondering why you are doing it that way. Tbh, I don't understand your actual problem from the description you give. – Gordon Apr 22 '16 at 11:00
  • well, everything is output in just one line when i open the csv file, and what i want is the days to appear below each other. instead of having two columns in the csv file like day1nh and day1eh...i want just one column day1nh and below this one (so one more line) it will appear day1eh – Japa Apr 22 '16 at 11:05
  • do you open the file in a browser or a text editor? if you open in it a browser, check the source code whether it's really on one line or just the browser not interpreting newline characters – Gordon Apr 22 '16 at 11:07
  • The file is suppose to be opened in excell. – Japa Apr 22 '16 at 11:11

0 Answers0