我正在使用WP_List_Table
类在后端创建一个从myCustomTable
获取记录的表。是否有任何功能/插件可用于导出单个&多行到CSV
格式。我尝试了很多插件,但他们都想出了整个表格。
由于
答案 0 :(得分:0)
<?php
include '../common/inc.common.php';//db connectivity
$class=$_REQUEST['class_id'];//get the class id
$line .= "\n";
$filename='../app/class_export_student_hsc.csv';// file name
$fp = fopen($filename, "w");
$sql="SELECT t1 . * ,y.aca_year
FROM (
SELECT name,fathername,school_name,edu_disctrict,revenue_disctrict,nationality,religion,caste,castetype,gender,dob,dobword,mark1,stat
FROM **myCustomTable**
)t1, academic_years y
WHERE t1.academic_year=y.refid
AND t1.class =$class
";
$studentArray=$Cobj->run_query($sql);
$line = "";
foreach($studentArray as $name => $valuee) {
$comma = "";
foreach($valuee as $key2 => $value){
$line .= $comma . '"' . str_replace('"', '""', $key2) . '"';
$comma = ",";
}
$line .= "\n";
break;
}
foreach($studentArray as $name => $valuee) {
$comma = "";
foreach($valuee as $key2 => $value){
$line .= $comma . '"' . str_replace('"', '""', $value) . '"';
$comma = ",";
}
$line .= "\n";
}
fputs($fp, $line);
fclose($fp);
if (file_exists($filename)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
readfile($filename);
exit;
}
?>