how can I download a table on mysql database using a PHP page?
Dear Experts,
how can I download mysql table as Excel using PHP page?
I want to download the table on the database as Excel not the existing PHP page...
thank you
PHPMySQL Server
Last Comment
BR
8/22/2022 - Mon
Julian Hansen
You have three options
1. CSV
2. XML
3. Library that handles Excel files.
I personally use XML - it is more versatile than CSV and not as top heavy as the libraries out there.
How does it work.
1. Make an Excel mockup of the data you want to export to Excel
2. Save it as an XML file
3. Make header and footer files from the XML by taking out the top part of the document (to the start of the table) and the bottom part (from the end of the table to the end of the document)
4. Take a sample row from the document - this becomes your template.
When you are outputing your file
1. Output the header (either to a temporary file or read it into a string)
2. Loop through your data and use the template to create the rows - add to the file / string from 2
3. Output your footer as above
4. Setup your headers to tell the browser you are sending an attachment (calc filesize and set name here)
5. die / exit
1. CSV
2. XML
3. Library that handles Excel files.
I personally use XML - it is more versatile than CSV and not as top heavy as the libraries out there.
How does it work.
1. Make an Excel mockup of the data you want to export to Excel
2. Save it as an XML file
3. Make header and footer files from the XML by taking out the top part of the document (to the start of the table) and the bottom part (from the end of the table to the end of the document)
4. Take a sample row from the document - this becomes your template.
When you are outputing your file
1. Output the header (either to a temporary file or read it into a string)
2. Loop through your data and use the template to create the rows - add to the file / string from 2
3. Output your footer as above
4. Setup your headers to tell the browser you are sending an attachment (calc filesize and set name here)
5. die / exit
Sample
Open in new window