I have a table within a mysql database. What i want to do, is in a php page, run a select statement and output the result into an excel file.
I've seen quite a few tutorials out there and tried them, however these output the contents of the webpage into the excel file. I just want the mysql table data and headers.
Is there a way to do this?
You can use one of the available PHP libraries for that. One, two.
One thing that is pretty fast to develop but not as neat as using a LIBRARY for that is:
application/vnd.ms-excel
In most browsers, using that page will open the HTML table as a spreadsheet in Excel. You can use other HTTP headers to suggest file name for that file.
I've used PHPExcel for quite a while now and I must say, it's pretty easy to use if you can read the doc.
Did what you want in an afternoon (reading the doc, trying stuff and finalizing)
Definitely you have to use a component to generate a Excel file. I use this lib:
Here is a small snippet: