문제

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();                    

        }
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top