Okay so, I am actually trying to create a CSV File through PHP that will look like this in Excel:
Name, Surname, Age
John, Daniel, 26
Mike, Daniel, 15
Alison, Daniel, 66
In order to do that, I save all the details in an array like this:
$csvarray[0] = "name, surname, age";
And for the rest I use a for loop (because I don't know how many people there are), like this:
for($x = 1; $x <= $max; $x ++) {
$name = $_POST ['age'];
$surname = $_POST ['age'];
$age = $_POST ['age'];
$csvarray[x] = "$name, $surname, $age"; }
This is the code I use in order to create the CSV file and save the details:
$csvfile = fopen("test.csv","w");
foreach ($csvarray as $line) {
fputcsv($csvfile,explode (',',$line));
}
fclose($file);
The problem is, when I open the file to check what is in there, all I see is row 0 and the last row of the final person. For example:
Name, Surname, Age
Alison, Daniel, 66
What am I doing wrong? Is there a smarter way to solve this? Thanks in advance.