Ver Mensaje Individual
  #9 (permalink)  
Antiguo 02/03/2014, 21:47
Coservicios1
 
Fecha de Ingreso: mayo-2011
Mensajes: 2
Antigüedad: 12 años, 11 meses
Puntos: 0
Respuesta: Exportar resultado de Consulta SQL a Excell desde PHP

Amigos necesito una ayuda urgente
Necesito llevar los resultados de esta consulta a excel me pueden colaborar

<?php
// http://programarenphp.wordpress.com

/******** CONECTAR CON BASE DE DATOS **************** */
/******** Recuerda cambiar por tus datos ***********/
$con = mysql_connect("localhost","root","1234");
if (!$con){die('ERROR DE CONEXION CON MYSQL: ' . mysql_error());}
/* ********************************************** */

/********* CONECTA CON LA BASE DE DATOS **************** */
$database = mysql_select_db("semate68_greenars",$con);
if (!$database){die('ERROR CONEXION CON BD: '.mysql_error());}
/* ********************************************** */

//ejecutamos la consulta
$sql = "SELECT cedula, nombres, tipolider,telefono1,celular,email,beneficio FROM lideres WHERE tipolider='"
.$_POST['tipolider']."'";
$result = mysql_query ($sql);
// verificamos que no haya error
if (! $result){
echo "La consulta SQL contiene errores.".mysql_error();
exit();
}else {
echo "<table border='1'><td>Cedula</td><td>Nombre</td><td>Tipo Lider</td><td>Telefono</td><td>Celular</td><td>Email</td><td>Beneficio</tr>";
//obtenemos los datos resultado de la consulta
while ($row = mysql_fetch_row($result))
{
echo "<tr><td width=\"15%\"><font face=\"verdana\">" .
$row[0] . "</font></td>";
echo "<td width=\"15%\"><font face=\"verdana\">" .
$row[1] . "</font></td>";
echo "<td width=\"15%\"><font face=\"verdana\">" .
$row[2] . "</font></td>";
echo "<td width=\"15%\"><font face=\"verdana\">" .
$row[3] . "</font></td>";
echo "<td width=\"15%\"><font face=\"verdana\">" .
$row[4] . "</font></td>";
echo "<td width=\"15%\"><font face=\"verdana\">" .
$row[5] . "</font></td>";
echo "<td width=\"15%\"><font face=\"verdana\">" .
$row[6]. "</font></td></tr>";
}
echo "</table>";
}
?>

La idea es que desde la pagina que tengo esta consulta por un boton pueda darle la opcion al usuario de llevar esta a un archivo de excel