Jump to content

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!

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.