napsternova
asked on
How to export MySQL Recordset Results to Excel
How can I enable the end-user to export the results from a RecordSet to Excel? My site uses PHP and a MySQL database. The Results page in a table format that is dynamic. The user will need to be able to click a button or link to save off an Excel file of the table’s results. I have no idea how to start this. I can only find extensions that take a form and insert the data into an Excel file.
Thanks
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome solutions, how about those extensions? Just for fun
PHP has some built-in capabilities to help you with this. Check the man page here:
http://us.php.net/manual/en/function.fputcsv.php#94088
Most Windows installations will automatically associate CSV files with Excel. So a good way to do something like this is to write the CSV file on your server and give the client an HTML link to the file. When they click the link, the Excel program will usually start.
http://us.php.net/manual/en/function.fputcsv.php#94088
Most Windows installations will automatically associate CSV files with Excel. So a good way to do something like this is to write the CSV file on your server and give the client an HTML link to the file. When they click the link, the Excel program will usually start.
ASKER
I am not too sure what to do with this, sorry.
So I can make a new php document and create a recordset?
Then enter the array info?
This info appears in 3 rows and 3 columns, how to I display my info that will always be say 3 columns but depending on how many items are in the repeating region could have 100 rows. This example is static. Can you help with this part?
<?php
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
So I can make a new php document and create a recordset?
Then enter the array info?
This info appears in 3 rows and 3 columns, how to I display my info that will always be say 3 columns but depending on how many items are in the repeating region could have 100 rows. This example is static. Can you help with this part?
<?php
$list = array (
array('aaa', 'bbb', 'ccc', 'dddd'),
array('123', '456', '789'),
array('"aaa"', '"bbb"')
);
$fp = fopen('file.csv', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
napsternova,
You've already closed out, but here are two extensions that will automate this:
http://linecraft.com/dreamweaver-export-to-excel/extension.php
http://www.dmxzone.com/go?16350
You've already closed out, but here are two extensions that will automate this:
http://linecraft.com/dreamweaver-export-to-excel/extension.php
http://www.dmxzone.com/go?16350
hth - flub