Hi to all... I need help for my script in php.. I have a form that queries certain results and display it in web. My problem is i need to get those web displayed results to download and export it in excel. Can someone help me on this? im not a php programmer and just starting to learn it.. thanks in advance!
in addition to my first post, i need to put a "download button or link" somewhere on that page so when i press it, it will download the displayed results and export to ms-excel.
Here's one that i made. Take note of the line on Bold, this is from the form page (WHERE YOU WANT YOUR BUTTON "download button or link") passing the array $_POST where it is parsed to xls format(excel), this is just basic formatting. <?php $records = $_POST['records']; function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); } $filename = "ra_work_units" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; foreach($records as $row) { if(!$flag) { echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> here is the array format $_POST = array('dbrow1'=>array('column11','column12','column13'),'dbrow2'=>array('column21','column22','column23'));
thank you for the quick reply... im just a little bit confused.. 1. so i need to create another php file that contains the code that you created right? to be able to call that file for my "download link" 2. $records represents the query results from the form page where i want to put the link button right? so if i have $results variable from the query form then i will change the $records to $results like $results=$_POST['results']; 3. where i will put this code? sorry im so dumb that i need to clarify this things..
hello wool01, In order to export data to Excel in php, there is a awesome excel library for php. It is phpexcel. Go to http://www.codeplex.com/PHPExcel to download the library. If you download the library, you can see some good examples like what you want. Hope it helps