2012-02-02 112 views
0

我想从使用php的Mysql创建一个excel文件。我发现这个链接: http://forums.digitalpoint.com/showthread.php?t=60681 并使用他的代码。然而,它产生一个错误如下:codeigniter中未定义的变量问题

A PHP Error was encountered  

Severity: Notice   

Message: Undefined variable: header  

Filename: controllers/export_database.php  

Line Number: 26 

我的代码在控制器:

public function export() 
    { 
$line1="ID\tProduct\tColor\tSales\t"; 
$line2="1\tPrinter\tGrey\t13\t"; 
$line3="2\tCD\tBlue\t15\t"; 
$line4="3\tDVD\tRed\t7\t"; 
$line5="4\tMonitor\tGreen\t4\t"; 
$line6="5\tTelephone\tBlack\t2\t"; 

$data="$line1\n$line2\n$line3\n$line4\n$line5\n$line6\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"; //line 26 
    } 

} 

我不知道为什么头是一个不确定的变量。有什么想法吗?感谢帮助。

回答

1

header()函数将该数据推送给您的浏览器。它不会创建$头变量,因此是错误。

删除$header