0

I'm confused. I have problem how to add more than one line in csv archive.

In $V I collect datas from some conditions. Then I count how many datas are collected $countLm++.

The following code is my last try.

 if ($V >= "1") {
    $countLm++;

    echo "Time:" . $row['DayTime'];
    echo "|| AvT :". round ($row['Val(1)'],2);
    echo " *C";
    echo "|| ALM :". round ($row['Val(2)'],2);
    echo "|| LM :" .round ($V, 2);
    echo " % ";;
    echo "<br />";
    
    $sumT += (round ($row['Val1'])'],2));
    $averageT = $sumT / $countLm ;
    
    $csvFile = "saving path";
    $handle = fopen($csvFile, "w");

    if ($handle === false) { 
        exit("Error creating $csvFile"); 
    }
    
    fputcsv($handle, ['DayTime','AvT','ALM','LM']);
    
    fputcsv($handle, [$row['DayTime'],  round ($row['Val(1)'],2),round ($row['Val(2)'],2), round ($V, 2)]);

    fclose($handle);
    
}

The problem is that I can "print" only one line in CSV. But I want to "print" more lines, as lines as $countLm is.

How can I add more lines? What can I modify?

Thanks for your advices!!!!!

ThP...
  • 5
  • 6
  • This might have what you're looking for: [https://stackoverflow.com/questions/17447442/printing-a-new-line-in-a-csv-file-cell](https://stackoverflow.com/questions/17447442/printing-a-new-line-in-a-csv-file-cell) – Fly_Moe Jan 08 '22 at 00:10
  • @Fly_Moe I tryied alot with this link before. When I used "\t" I lose my comma. When I used "\r\n" or "\n" my printed line separated value by value in new line. – ThP... Jan 08 '22 at 00:16
  • Does this answer your question? [Import multiple csv files into pandas and concatenate into one DataFrame](https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe) – pringi Jan 10 '22 at 14:08

0 Answers0