在尝试创建excel文件时,我收到警告:无法修改标头信息

时间:2014-09-10 19:05:47

标签: php

我有一个PHP代码将数据从mysql导出到excel表。

export_customer.php

<?php
         include 'psl-config.php';
         function export_excel_csv(){

      $cust_name = $_GET['msg'];
      $conn = mysql_connect(HOST, USER, PASSWORD);
      $db = mysql_select_db(DATABASE,$conn); 
      $sql = "Select t1.custi_id_fk, t2.full_name, t2.phone_1, t2.phone_2, t1.amount from outwards_credit As t1 INNER JOIN cust_info As t2 ON t1.custi_id_fk = t2.cust_id where t1.bill_state = 0 and t1.custi_id_fk = ". $cust_name;

     $rec = mysql_query($sql) or die (mysql_error());

      $num_fields = mysql_num_fields($rec);

      for($i = 0; $i < $num_fields; $i++ )
      {
          $header .= mysql_field_name($rec,$i)."\\t";
      }

      while($row = mysql_fetch_row($rec))
      {
          $line = '';
          foreach($row as $value)
          {                                            
              if((!isset($value)) || ($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 No Record Found!\n";                        
      }
      header("Content-type: application/octet-stream");
      header("Content-Disposition: attachment; filename=reports.xls");
      header("Pragma: no-cache");
      header("Expires: 0");
      print "$header\\n$data";
  }
       if(isset($_GET['msg'])){ 

    export_excel_csv();
     } else {
         echo "There are no data";
     }

     ?>

我用另一个文件中的href来调用它:

<a href= export_customer.php?msg=1> Export </a>

但我最终得到以下错误。

警告:无法修改标题信息 - 第45行的/includes/export_customer.php中已经发送的标题(在/includes/export_customer.php:1处开始输出)

警告:无法修改标题信息 - 第46行/includes/export_customer.php中已经发送的标题(输出从/includes/export_customer.php:1开始)

警告:无法修改标题信息 - 已在第47行的/includes/export_customer.php中发送的标题(在/includes/export_customer.php:1处开始输出)

警告:无法修改标题信息 - 第48行/inludes/export_customer.php中已发送的标题(输出从/includes/export_customer.php:1开始) custi_id_fk \ tfull_name \ tphone_1 \ tphone_2 \ tamount \吨\ n&#34; 1&#34; \ T&#34;顾客&#34; \ T&#34; 123123&#34; \ T&#34; 987987&#34; \ T&# 34; 100.00&#34; \吨\ n&#34; 1&#34; \ T&#34;顾客&#34; \ T&#34; 123123&#34; \ T&#34; 987987&#34; \ T&#34; 10000.00&#34; \吨\ n

我哪里错了???

0 个答案:

没有答案