问题描述:

Okay I have been going at this for days now! I have a webpage that allows users to select elements which will run a query from my database table. The results are then shown in an HTML table. I created a checkbox that when checked it is supposed to download a CSV file of the results when submitted. The problem is nothing happens! On the webpage the csv headers(Network, Zone...etc) keeps displaying and i don't want it to do that. Those headers are supposed to be in the CSV file with the results from the query. Can someone please tell me what I am doing wrong? The snippet is the part that I am having trouble with. Anything helps!

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)

相关阅读:
Top