I am trying to export data from MySQL to CSV using PHP from a website. When a user clicks generate the report it will automatically create and this will be downloaded as a file on their computer. The code below I have been following an online tutorial but I have run into some issues. Currently, it will download but will only show one row with one date value from the mySQL data.
I was wondering what I need to do to show all the data in the csv file and how do I ensure that the names of the Rows are printed as well. Any help would be great!
@header("Content-Disposition: attachment; filename=fibromerecord.csv");
$select = "SELECT * FROM DBtable WHERE user_id=$id";
$result2=$conn->query($select);
while($row=$result2->fetch_assoc()){
$data=$row['pain']."\n";
$data=$row['sleep']."\n";
$data=$row['mood']."\n";
$data=$row['heartrate']."\n";
$data=$row['time_of_entry']."\n";
}
echo $data;
exit();
Aucun commentaire:
Enregistrer un commentaire