Exporting the data into a csv file is working correctly but the problem when trying to open the csv file displaying a line gap between each record.
Added this line because earlier if i open the file in notepad it is displaying all the data in a single line so added this line after that it working fine in notepad but faced problem in CSV format getting a line gap before each record.
fwrite($output,"\r\n");
$txtstartdate=$_POST['txtstartdate'];
$txtenddate=$_POST['txtenddate'];
header('Content-Type:text/csv;charset=utf-8');
header('Content-Disposition:attachment;filename=appointmentlist.csv');
$output = fopen('php://output','w');
fputcsv($output,array('Appointment Id','First name','Last Name','Email','Gender','Department','Phone Number','Appointment Date','Address','Status'));
$query = "select * from appointment WHERE date BETWEEN '$txtstartdate' AND '$txtenddate' ORDER BY date DESC";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_assoc($result))
{
fwrite($output,"\r\n");
fputcsv($output,$row);
}
fclose($output);
If i open in Notepad it is displaying like this
NOTEPAD:
"Appointment Id","First name","Last Name",Email,Gender,Department,"Phone Number","Appointment Date",Address,Status
2,aaa,bbbb,ccc@gmail.com,male,physician,9606567652,2018-10-04,"ctc,odisha",0
3,nas,maha,shu@gmail.com,male,physician,9207644052,2018-10-04,"ctc,odisha",0
In CSV it is displaying one row gap after each record.So i don't want to display gap after each record in CSV file.