好的,我已经在这几天了!我有一个网页,允许用户选择将从我的数据库表运行查询的元素。然后结果显示在HTML表格中。我创建了一个复选框,当选中它时,它应该在提交时下载结果的CSV文件。问题是没有任何反应!在网页上,csv标题(网络,区域等)不断显示,我不希望它这样做。这些标题应该在CSV文件中,并带有查询结果。有人可以告诉我我做错了什么吗?该片段是我遇到麻烦的部分。一切都有帮助!
if($csv == 1) {
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=wct.csv");
header("Pragma: no-cache");
header("Expires: 0");
$outstream = fopen("php://output",'w');
fputcsv($outstream, array('Network', 'Zone', 'Vendor', 'Element', 'Element Type', 'Service','Product', 'T1 Manager', 'T2 Manager', 'T3 Manager', 'T4 Manager', 'Config Manager', 'Capacity Manager', 'Current Planning', 'ENG Manager', 'FNP Manager', 'Wiki')); //This keeps displaying on webpage!!!
foreach ($_POST["toos"] as $to) {
$sql = "SELECT * FROM networkelements WHERE element = '$to' GROUP BY network, zone, vendor, element ";
$result = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_assoc($result)) {
//print_r(array_values($row)); //will print out to webpage if uncommented
$csv_cont = print_r(array_values($row, true)); //stores array in a variable
fputcsv($outstream, $csv_cont); // supposed to put results in to a csv file but it doesn't.
} //while $result
} //foreach
} //if($csv)