redo Posted July 19, 2007 Share Posted July 19, 2007 hai ive got some problem...actually i know nothing about php..my supervisor ask me to export data to ms excel using php..its like there's a table that contain data then there's a button(export to ms excel) in webso plz someone.. Link to comment Share on other sites More sharing options...
Lulzim Posted July 19, 2007 Share Posted July 19, 2007 There are a lot of tutorials availablethis is a good one:http://www.phpfreaks.com/tutorials/114/0.php Link to comment Share on other sites More sharing options...
redo Posted July 20, 2007 Author Share Posted July 20, 2007 There are a lot of tutorials availablethis is a good one:http://www.phpfreaks.com/tutorials/114/0.php ...thanks a lot Lulzim...i'll check it out.... Link to comment Share on other sites More sharing options...
redo Posted July 20, 2007 Author Share Posted July 20, 2007 i already done the coding but the button is not working.. plz help memy coding like this<input name="cmdHantar" type="submit" class="btn" id="cmdHantar" value="Eksport kepada Ms Excel">if(isset($_POST['cmdHantar'])) { switch($_POST['cmdHantar']) {case 'Eksport kepada Ms Excel': $select = "select * from basicdata_pembuatan"; $export = mysql_query($select); $fields = mysql_num_fields($export); for($i=0; $i< $fields; $i++) { $header .= mysql_field_name($export,$i). "\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset ($value)) or ($value =="")) { $value = "\t"; } else { $value = str_replace('"','""',$value); $value = '"' . $value . '"' . "\t"; } $line .=$value; } $data .= trim($line). "\n"; } $data = str_replace("\r","",$data); if($data =="") { $data = "\n(0) Records Found!\n"; } header ("Content-type: application/x-msdownload"); header ("Content-Disposition: attachment; filename=extraction.xls"); header ("Pragma : no-cache"); header ("Expires: 0"); print "header\n$data"; break; }} Link to comment Share on other sites More sharing options...
Lulzim Posted July 20, 2007 Share Posted July 20, 2007 you should add the php opening and closing tags <?php and ?>also you should write a form, specify the action and method. <?phpif(!isset($_POST['cmdHantar'])){echo "<form action='filename.php' method='post'>";echo "<input name='cmdHantar' type='submit' class='btn' id='cmdHantar' value='Eksport kepada Ms Excel'>";echo "</form>";}else{switch($_POST['cmdHantar']){case 'Eksport kepada Ms Excel':$select = "select * from basicdata_pembuatan";$export = mysql_query($select);$fields = mysql_num_fields($export);for($i=0; $i< $fields; $i++){$header .= mysql_field_name($export,$i). "\t";}while($row = mysql_fetch_row($export)){$line = '';foreach($row as $value){if ((!isset ($value)) or ($value =="")){$value = "\t";}else{$value = str_replace('"','""',$value);$value = '"' . $value . '"' . "\t";}$line .=$value;}$data .= trim($line). "\n";}$data = str_replace("\r","",$data);if($data ==""){$data = "\n(0) Records Found!\n";}header ("Content-type: application/x-msdownload");header ("Content-Disposition: attachment; filename=extraction.xls");header ("Pragma : no-cache");header ("Expires: 0");print "header\n$data";break;}}?> Link to comment Share on other sites More sharing options...
redo Posted July 23, 2007 Author Share Posted July 23, 2007 hai lulzim...ive got some error...it says..Notice: Undefined variable: header in C:\wamp\www\basicdata\interface\dtpr101.php on line 87Notice: Undefined variable: data in C:\wamp\www\basicdata\interface\dtpr101.php on line 106Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\basicdata\main\config.php:30) in C:\wamp\www\basicdata\interface\dtpr101.php on line 115Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\basicdata\main\config.php:30) in C:\wamp\www\basicdata\interface\dtpr101.php on line 116Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\basicdata\main\config.php:30) in C:\wamp\www\basicdata\interface\dtpr101.php on line 117Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\basicdata\main\config.php:30) in C:\wamp\www\basicdata\interface\dtpr101.php on line 118header "1" "07" "2007" "22" "232" "45" "678" "test" "2007-07-10 12:19:55" "2" "05" "2006" "21" "132" "22" "687" "test" "2007-07-10 12:19:55" "3" "06" "2007" "20" "213" "33" "634" "test" "2007-07-10 12:19:55" i dont know why.. : ( Link to comment Share on other sites More sharing options...
redo Posted July 23, 2007 Author Share Posted July 23, 2007 i've got the ans...thanks alot lulzim.... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.