如何在PHP中导出mysql表数据 [英] How to export mysql table data in PHP
本文介绍了如何在PHP中导出mysql表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我导出到excel的代码,但它显示数据列表而不是以excel导出
this is my code to export to excel, but it display the data list and not to export in excel
function ExportToExcel($requests){
//print_r($requests);//exit;
extract($requests);
$query = "SELECT * FROM ".$tname." P WHERE 1";
$cond_search = '';
$Querycond = '';
if(isset($dwnld) && ($dwnld == "dwnld_all")){
$Querycond .= " AND 1 ";
}
if(isset($dwnld) && ($dwnld == "new_submission")){
$Querycond .= " AND apply_on >= CURDATE()";
}
if(isset($dwnld) && ($dwnld == "all_submission")){
$Querycond .= " AND 3";
}
$query .= $Querycond;
$query1 = $query . " ORDER BY P.apply_on desc";
$setRec = mysql_query($query1);
$developer_records = array();
while( $rows = mysql_fetch_assoc($setRec) ) {
$developer_records[] = $rows;
}
$filename = "export_".date('Ymd') . ".xls";
header("Content-type: application/octet-stream");
header("Content-Type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: attachment; filename='".$filename."'");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Cache-Control: max-age=0');
$show_coloumn = false;
if(!empty($developer_records)) {
foreach($developer_records as $record) {
if(!$show_coloumn) {
// display field/column names in first row
echo implode("\t", array_keys($record)) . "\n";
$show_coloumn = true;
}
echo implode("\t", array_values($record)) . "\n";
}
}
exit;
return true;
}
我的尝试:
请帮帮我,如何解决它,我已经在ajax调用php文件然后将php文件转到另一个php文件
What I have tried:
please help me, how to solve it,i have did in ajax call to php file then that php file to another php file
推荐答案
请求){
// print_r(
requests){ //print_r(
requests); //退出;
extract(
requests);//exit; extract(
requests);
requests);
这篇关于如何在PHP中导出mysql表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文