I am trying to write 2 arrays to csv file using fputcsv.
But the problem is when writing the second array it goes to the end of the file and starts from there.
So basically I have these 2 sections to write in a csv file and it's writing in the following way
ID Name1
1 AAA
2 BBB
Name2
CCC
DDD
What I want
ID Name1 Name2
1 AAA CCC
2 BBB DDD
My code is
fputcsv($fh, array("ID","Name1"));
while($row = mysqli_fetch_array($weekly1, MYSQLI_NUM))
{
fputcsv($fh, array($row[0],$row[1]));
}
fputcsv($fh, array("Name2"));
while($row = mysqli_fetch_array($weekly2, MYSQLI_NUM))
{
fputcsv($fh, array($row[1]));
}
Is there any way to overcome this problem. Any help or suggestion is highly welcomed.Thanks in advance.