I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.
I have the e-mailing of the link, MySQL query, etc. covered.
How can I, when they click the link, have a pop-up to download a CVS with the record from MySQL?
I have all the information to get the record already. I just don't see how to have PHP create the CSV file and let them download a file with a .csv extension.
Here is a full working example using PDO and including column headers:
Here is one I have done before, grabbing data between certain dates. Hope it helps.
Create your file then return a reference to it with the correct header to trigger the Save As - edit the following as needed. Put your CSV data into $csvdata.
In addition to all already said, you might need to add:
It's very useful when handling files with multiple languages in them, like people's names, or cities.
How to write in CSV file using PHP script? Actually I was also searching for that too. It is kind of easy task with PHP. fputs(handler, content) - this function works efficiently for me. First you need to open the file in which you need to write content using fopen($CSVFileName, ‘wb’).