Jump to content

[SOLVED] file export woe's


Yammyguy

Recommended Posts

Hello all.. 

 

I'm new to this forum, and I'm hoping someone can help me out with this problem.  I'm probably just shy of being considered an intermediate in the PHP world, I like to just jump right in and learn along the way...

 

Here's my problem:  I have a two page application.  First page uploads CSV files, parses it out, and inserts it into a database.

 

The second page displays a populated table containing data from the database depending on a key value - VERY straightforward, really.  The second page also has an option to export the table to a .xls file.  As of now, the "export to excel" option will prompt to save with appropriate file name, but the file is just the HTML of that page.  Here's the code for the second page:

 

<?php
$sExport = @$HTTP_GET_VARS["export"];

if ($sExport == "excel") {
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=EarthHour.xls');
}

if($sExport == "nsls"){

//query database based on NSLS sources
db_connect(nsls);

} else if($sExport == "ms1") {

//query database based on ms1 sources
db_connect(ms1);

} else if($sExport == "ms2") {


//query database based on ms2 sources
db_connect(ms2);

}

function db_connect($source){
$conn = mysql_connect('localhost', '$user', '$pass');
mysql_select_db('lakeland',$conn);
$sql = "SELECT date,time,KV,kVAr,kVA,PF
	FROM demand where source = '$source'
	ORDER by date ASC";
$result = mysql_query($sql, $conn);
echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"75%\" align=\"center\"><tbody>";
echo "<tr><td colspan=\"6\" align=\"center\">Hourly Interval <b>'$source'</b> data from 20:30 to 21:30</td></tr>";
echo "<tr align=\"center\">";
echo "<td> Date</td>";
echo "<td> Time</td>";
echo "<td> KW</td>";
echo "<td> kVAr</td>";
echo "<td> kVA</td>";
echo "<td> PF</td>";
echo "</tr>";
while($row = mysql_fetch_array($result)){
	echo "<tr>";
	echo "<td align=\"center\">".$row["date"]."</td>";
	echo "<td align=\"center\">".$row["time"]."</td>";
	echo "<td align=\"center\">".$row["KV"]."</td>";
	echo "<td align=\"center\">".$row["kVAr"]."</td>";
	echo "<td align=\"center\">".$row["kVA"]."</td>";
	echo "<td align=\"center\">".$row["PF"]."</td>";
	echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}
?>
<br>
<br>
<div align="center"><a href="myupload.php">Back</a>  <a href="display.php?export=excel">Export to Excel</a></div>

 

As soon as I added the options for all the $sExport == "nsls" or "ms1" or "ms2" the excel export no longer worked.  Before I put these, the export worked like a charm!

 

what am I missing??? ??? ??? ??? ???

 

Please let me know you need anymore information. 

Thanks very much in advance!

 

~C.

Link to comment
https://forums.phpfreaks.com/topic/147843-solved-file-export-woes/
Share on other sites

No, it's not that since I can display the whole table, and properly export as xls..

 

it's something to do with the HTTP_GET_VARS['export'] for the excel export, and the IF statements for querying the tables at the top.

 

it just doesn't make sense!  i'm pulling my hair out!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.