Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/01/2010, 21:07
oscarjosue
 
Fecha de Ingreso: octubre-2008
Mensajes: 26
Antigüedad: 15 años, 7 meses
Puntos: 0
reportes en excel en php

que tal tengo un peque problema, necesito hacer unos repostes en excel, pero primero se tiene que ver el resultado de mi consulta en pantalla, y con el codigo que tengo me manda directo el reporte a excel, lo que no eh podido es poner un boton de modo que se vea primero la consulta en pantalla y una vez que yo quiera le de clic al boton y lo mande a excel, espero me puedan ayudar, este es mi codigo:

<?php

//if(isset($_REQUEST['btnExportarExcel'])){
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=nombre_archivo.xls");
//}
?>

<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "../../index.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "../../index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
body,td,th {
color: #CCCCCC;
}
body {
background-color: #990000;
}
-->
</style></head>

<body>

<p>&nbsp;<a href="<?php echo $logoutAction ?>">Desconectar</a></p>
<p>
<?php
//if (!isset($CARRERA_EGRESO)){
//echo "Debe especificar una cadena a bucar";
//echo "</html></body> \n";
//exit;
//}

$host="localhost";
$user="root";
$password="root";
$db="usuarios";
$CARRERA_EGRESO=$_POST["select"];
$ESPECIALIDAD=$_POST["select2"];
$TITULADO=$_POST["select3"];
$enlace = mysql_connect($host,$user,$password) or die ("No se puede conectar con el servidor");
mysql_select_db($db,$enlace) or die ("No se puede seleccionar la base de datos");
$consulta = mysql_query("SELECT * FROM perfil_prueba WHERE CARRERA_EGRESO LIKE '%$CARRERA_EGRESO%' and ESPECIALIDAD LIKE '%$ESPECIALIDAD%' and TITULADO LIKE '%$TITULADO%'", $enlace);
//$result=mysql_query($consulta) or die( "Error en query: $consulta, el error es: " . mysql_error() );

while($row = mysql_fetch_array($consulta))
{

$NUMERO_CONTROL= $row["NUMERO_CONTROL"];
$APELLIDO_PATERNO= $row["APELLIDO_PATERNO"];
$APELLIDO_MATERNO= $row["APELLIDO_MATERNO"];
$NOMBRE_S= $row["NOMBRE_S"];
$CARRERA_EGRESO= $row["CARRERA_EGRESO"];
$ESPECIALIDAD= $row["ESPECIALIDAD"];
$SEMESTRE_EGRESO= $row["SEMESTRE_EGRESO"];
$ANO_EGRESO= $row["ANO_EGRESO"];
$TITULADO= $row["TITULADO"];
echo("<table width='100%' border='7' cellspacing='1' callpadding='1'>\n");
echo("<tr>\n");
echo("<td width='10%'>$NUMERO_CONTROL</a></td>\n");
echo("<td width='15%'>$APELLIDO_PATERNO</a></td>\n");
echo("<td width='15%'>$APELLIDO_MATERNO</a></td>\n");
echo("<td width='20%'>$NOMBRE_S</a></td>\n");
echo("<td width='30%'>$CARRERA_EGRESO</a></td>\n");
echo("<td width='30%'>$ESPECIALIDAD</a></td>\n");
echo("<td width='20%'>$SEMESTRE_EGRESO</a></td>\n");
echo("<td width='8%'>$ANO_EGRESO</a></td>\n");
echo("<td width='5%'>$TITULADO</a></td>\n");
echo("</tr>\n");
echo("</table>\n");
echo"<hr size = 2color =ffffff width = 100% align = left>";
}
?>
</p>
<p><a href="formbuscacarrera.php">Regresar</a></p>
</body>
</html>

esta pantalla le mando llmar desde otra, en donde tengo mi formulario.