I am receiving several fields from another form and based on them I generate a table and I have a button to generate the excel based on the generated table, this I do in reportExcel.php and after I send the query (with a echo) to ReporteExcel5.php but I would like instead of sending you an echo, better send the query so that the manager does not double work any ideas?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>Estatus completos</title>
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css" media="screen" />
<center>
<img src="images/santander1.png" alt="Banco santander.">
<h1>Consultar tokens 26 mar</h1>
</center>
</head>
<body>
<table id="Jtabla" cellpadding="0" cellspacing="0" border="0" class="display" >
<thead>
<tr>
<th width="58" align="left">Supertoken</th>
<th width="274" align="left">Numero de Buc</th>
<th width="119" align="left">Tipo de token</th>
<th width="103" align="left">estatus del token</th>
<th width="274" align="left">Numero de caja</th>
<th width="274" align="left">Sucursal</th>
<th width="274" align="left">Region</th>
<th width="124" align="left">Fecha de Captura</th>
</tr>
</thead>
<tbody>
<?php
require('conexion_bd/conexion.php');
require('conexion_bd/catalogo_funciones.php');
require('conexion_bd/ExportarReporteExcel.php');
//require('ReporteExcel3.php');
Connect();
$estatus_token = $_POST['estatus_token'];
$tipo_token = $_POST['tipo_token'];
$estatus_bboo = $_POST['estatus_bboo'];
$supertoken_id = $_POST['supertoken_id'];
$num_bug = $_POST['num_bug'];
$n_caja = $_POST['n_caja'];
$fecha_cap = $_POST['datepicker'];
$fecha_fin = $_POST['datepicker2'];
$fecha_inicial = date('Y-m-d',strtotime($fecha_cap));
$fecha_final = date('Y-m-d',strtotime($fecha_fin));
$sql = "SELECT * FROM tablacompleta where fecha_sistema BETWEEN '2018-02-20 00:00:00' AND '2018-02-26 23:00:00'";
$result =EjecutaConsultas($sql);
// while ($row = $result->fetch_assoc())
while ($row=mysql_fetch_array($result))
{
echo "<tr>
<td>".$row['supertoken_id']."</td>
<td>".$row['num_bug']."</td>
<td>".$row['tipo_token']."</td>
<td>".$row['estatus_token']."</td>
<td>".$row['n_caja']."</td>
<td>".$row['sucursal']."</td>
<td>".$row['region']."</td>
<td>".$row['fecha_sistema']."</td>
</tr>";
?>
<?php
}// fin del while
?>
</tbody>
</table>
<script>
$(document).ready(function() {
$('#Jtabla').dataTable(
{
"language": {
"lengthMenu": 'Mostrar <select>'+
'<option value="50">50</option>'+
'<option value="100">100</option>'+
'<option value="200">200</option>'+
'<option value="300">300</option>'+
'<option value="400">400</option>'+
'<option value="-1">Todos los registros</option>'+
'</select> registros',
"aoColumnDefs":null,
}
} //fin
);
} );
function numeros(evt)
{
//alert("Me haz dado un click");
// $archivo='php://output';
//CrearReporteExcelNafinet($result,$archivo);
}
</script>
<center>
<form action="ReporteExcel5.php" method="POST">
<input type="submit" value="Generar Reporte excel">
<input type="hidden" id="query" name="query" value="<?php echo $sql; ?>" />
</form>
</center>
</body>
</html>
<?php
error_reporting(E_ALL);
ini_set('include_path',ini_get('include_path').';ClassesExcel/');
include("includes/ClassesExcel/PHPExcel.php");
include ('includes/ClassesExcel/PHPExcel/Writer/Excel2007.php');
require('conexion_bd/conexion.php');
if (PHP_SAPI == 'cli')
die('');
require_once dirname(__FILE__) . '/includes/ClassesExcel/PHPExcel.php';
$query = $_POST['query'];
Connect();
$resultado =EjecutaConsultas($query);
$i=2;
$pag=0;
$objPHPExcel = new PHPExcel();
$fechaBD = date('Y-m-d');
while(@$dato = mysql_fetch_array($resultado))
{
////////ENCABEZADO/////////
$objPHPExcel->setActiveSheetIndex($pag)
->setCellValue('A1', "Supertoken")
->setCellValue('B1', "Numero de Caja")
->setCellValueExplicit('C1',"Motivo")
->setCellValueExplicit('D1',"Operador")
->setCellValueExplicit('E1',"Fecha de Recepcion")
->setCellValueExplicit('F1',"Tipo token")
->setCellValueExplicit('G1',"Numero de buc")
->setCellValueExplicit('H1',"Fecha de captura")
->setCellValue('A'.$i, $dato["supertoken_id"])
->setCellValue('B'.$i, $dato["n_caja"])
->setCellValueExplicit('C'.$i,$dato["motivo"])
->setCellValue('D'.$i, $dato["operador"])
->setCellValueExplicit('E'.$i, $dato["fecha_cap"])
->setCellValue('F'.$i, $dato["tipo_token"])
->setCellValueExplicit('G'.$i, $dato["num_bug"])
->setCellValueExplicit('H'.$i, $dato["fecha_sistema"]);
// ->setCellValueExplicit('I'.$i,$fechaBD)
$i++;
;
}
$objPHPExcel->getActiveSheet()->setTitle('Descarga');
$objPHPExcel->setActiveSheetIndex(0);
$fecham=date('d-m-Y');
$nombrearchivo='Descarga'.$fecham;
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$nombrearchivo.'.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');
//$objWriter->save('C:/Descargas/Cartera/' . $nombrearchivo . '.xlsx');
exit;
?>