Question

Not outputting anything in csv file. Please help!!

This print_r($list).

outputs everything in the database in the right format But when i try to put the into a csv file only one line gets outputted.

$sql = "select * from " . TABLE_ORDERS . "";
          $result = $db->Execute($sql);

      if ($result->RecordCount() > 0) {
          while (!$result->EOF) {

        $file_date = date("d_m_Y_G_i_s");
        $filename = "../weight/weightExport_".$file_date .".csv";  

        $customers_Name =  $result->fields['customers_name']; 

        $list = array($customers_Name);

        //print_r($list)."<br/>";

        $handle = fopen($filename, 'w+');

        fputcsv($handle, array('Username'));

        fputcsv($handle, $list);

        fclose($handle);


        $result->MoveNext();                    

        }
}
Was it helpful?

Solution

Change $handle = fopen($filename, 'w+');

to $handle = fopen($filename, 'a+');

It's only one line, because w+ is doing a truncate on that file. a+ is the append mode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top