mamasita60440
Programmer
I am trying to export contents from a php page to an excel spreadsheet. I am not an expert so my code may not be as sophisticated. For some reason the variables from the previous page are not posting even though I have created a session and listed the variables. Here is the code for the page where the variables that will be exported to the excel sheet should come from this page called 'displayReportData.php':
<?php session_start();
$_SESSION["ReportData"]=$_POST["ReportData"];
$_SESSION["PerformanceID"]=$_POST["PerformanceID"];
$_SESSION["HandleName"]=$_POST["HandleName"];
$_SESSION["ServerName"]=$_POST["ServerName"];
$_SESSION["LoadName"]=$_POST["LoadName"];
$_SESSION["InstallDate"]=$_POST["InstallDate"];
?>
<form action="tryexcel.php" method= "post" name="FormName">
<html>
<body>
<table>
<table border='1'>
<tr><th>Handle</th><th>Load</th><th>Server</th><th>Installation Date</th><th>Performance ID</th>
</tr>
<?php
foreach ($_POST['ReportData'] as $cbox=>$cboxvalue) {
$HandleName= $_POST["HandleName"][$cbox];
$LoadName= $_POST["LoadName"][$cbox];
$ServerName= $_POST["ServerName"][$cbox];
$InstallDate= $_POST["InstallDate"][$cbox];
$PerformanceID= $_POST["ReportData"][$cbox];
echo "<tr><td>".$HandleName."</td>
<td>".$LoadName."</td>
<td>".$ServerName."</td>
<td>".$InstallDate."</td>
<td>".$PerformanceID."</td>
</tr>";
}
?>
</table>
<br><br><input type="Submit" value="Display Graphs">
</form>
</body>
</html>
The information displayed on this page named 'tryexcel.php' should be exported to the excel spreadsheet. Here is the code:
<?php session_start();
$PerformanceID=$_SESSION["ReportData"]=$_POST["ReportData"];
?>
<?php
$db_host = "gpb";
$db_user = "ott";
$db_pwd = "77";
$db_name = "_run";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<?php
$select = "SELECT * FROM Peformance where PerformanceID='$PerformanceID' ";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
?>
<?php
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
?>
<?php
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
?>
<?php
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
?>
<?php
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
I am not looking for a free lunch. I have been working on this for quite some time. Any assistance you can offer is greatly appreciated.
In sum, I am trying to get the information stored in the 'PerformanceID' variable on the 'displayReportData.php' page to post on the 'tryexcel.php' so that the data with those performance id's will be exported to excel. Thank you for help in advance.
<?php session_start();
$_SESSION["ReportData"]=$_POST["ReportData"];
$_SESSION["PerformanceID"]=$_POST["PerformanceID"];
$_SESSION["HandleName"]=$_POST["HandleName"];
$_SESSION["ServerName"]=$_POST["ServerName"];
$_SESSION["LoadName"]=$_POST["LoadName"];
$_SESSION["InstallDate"]=$_POST["InstallDate"];
?>
<form action="tryexcel.php" method= "post" name="FormName">
<html>
<body>
<table>
<table border='1'>
<tr><th>Handle</th><th>Load</th><th>Server</th><th>Installation Date</th><th>Performance ID</th>
</tr>
<?php
foreach ($_POST['ReportData'] as $cbox=>$cboxvalue) {
$HandleName= $_POST["HandleName"][$cbox];
$LoadName= $_POST["LoadName"][$cbox];
$ServerName= $_POST["ServerName"][$cbox];
$InstallDate= $_POST["InstallDate"][$cbox];
$PerformanceID= $_POST["ReportData"][$cbox];
echo "<tr><td>".$HandleName."</td>
<td>".$LoadName."</td>
<td>".$ServerName."</td>
<td>".$InstallDate."</td>
<td>".$PerformanceID."</td>
</tr>";
}
?>
</table>
<br><br><input type="Submit" value="Display Graphs">
</form>
</body>
</html>
The information displayed on this page named 'tryexcel.php' should be exported to the excel spreadsheet. Here is the code:
<?php session_start();
$PerformanceID=$_SESSION["ReportData"]=$_POST["ReportData"];
?>
<?php
$db_host = "gpb";
$db_user = "ott";
$db_pwd = "77";
$db_name = "_run";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
<?php
$select = "SELECT * FROM Peformance where PerformanceID='$PerformanceID' ";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
?>
<?php
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
?>
<?php
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
?>
<?php
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
?>
<?php
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
I am not looking for a free lunch. I have been working on this for quite some time. Any assistance you can offer is greatly appreciated.
In sum, I am trying to get the information stored in the 'PerformanceID' variable on the 'displayReportData.php' page to post on the 'tryexcel.php' so that the data with those performance id's will be exported to excel. Thank you for help in advance.