PHP,如何将具有多个表的数据库导出到具有多个工作表的单个excel文件中?

时间:2018-11-30 20:37:11

标签: php mysql excel phpmyadmin

如何将几个选定的表导出到单个Excel文件中,而每个表又一个表?

下面是我当前的代码。

$con = mysqli_connect("localhost","root","","test1");

if(isset($_POST["download"]))  
 {  

      header('Content-Type: text/csv; charset=windows-1257');  
      header('Content-Disposition: attachment; filename=TEST.csv');  
      $output = fopen("php://output", "w");  
      fputcsv($output, array( 'ID', 'Name','type'));  
      $query = "SELECT * from table1";  
      $result = mysqli_query($con, $query);  
      while($row = mysqli_fetch_assoc($result))  
      {  
           fputcsv($output, $row);  
      }  
      fclose($output);  
 }  

0 个答案:

没有答案