Foros del Web » Programando para Internet » PHP »

¿Como exportar datos a excell usando un checkbox?

Estas en el tema de ¿Como exportar datos a excell usando un checkbox? en el foro de PHP en Foros del Web. Hola a todos nuevamente pues tengo la suiguiente duda ¿Quiero exportar registros de una consulta?, el detalle qeu no es exportar todos los registros y ...
  #1 (permalink)  
Antiguo 17/07/2009, 11:03
 
Fecha de Ingreso: septiembre-2003
Mensajes: 182
Antigüedad: 20 años, 7 meses
Puntos: 1
Información ¿Como exportar datos a excell usando un checkbox?

Hola a todos nuevamente pues tengo la suiguiente duda ¿Quiero exportar registros de una consulta?, el detalle qeu no es exportar
todos los registros y que me los generee en un archivo, si no de la consulta que realizo del lado izquierdo aparece una caja de seleccion
osea un "checkbox" y cuando seleccione uno o dos registros o los que sea me exporte esos registro que estoy seleccionando.


Aqui dejo el codigo donde me arroja el resultado la consulta:

<HTML>
<HEAD>
<TITLE>C.I.V.A</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">

</HEAD>
<BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<center>
<p>&nbsp;</p>
<table width="800" border="0">
<tr>
<th width="746" scope="col"><TABLE WIDTH=790 height="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0 bordercolor="#FFFFC1" bgcolor="#FFFFFF">
<tr bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<TD width="790"><table width="108%" border="0" align="center" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
<tr>
<td width="31%" height="84" bgcolor="#FFFFFF"><img src="logos/logo%20general.jpg" width="249" height="74"></td>
<td width="69%" bgcolor="#FFFFFF"><p align="left" class="style7"><strong><font color="#000000">
VICTIMAS DEL DELITO Y SERVICIOS A LA COMUNIDAD</font></strong></p>
<p align="left"><span class="style7"><font color="#000000"><strong>DIRECCION GENERAL DE ATENCION
A VICTIMAS DEL DELITO</strong></font><font color="#000000"><strong></strong></font></span></p></td>
</tr>
</table></TD>
</tr>
<TR>
<TD height="11">&nbsp;</TD>
</TR>
<TR>
<TD height="60%" bgcolor="#FFFFFF"><table width="88%" height="46" border="1" align="center" bordercolor="#000000">
<tr>
<td bgcolor="#FFFFC1"><form name="form1" method="post" action="procesabuscapartado.php">
<p>
<?php
include("includes/cnx.php");
if (isset($_POST['centros']) AND isset($_POST['campos1']))
{
mysql_real_escape_string($_POST['c_busqueda1']);
mysql_real_escape_string($_POST['centros']);
mysql_real_escape_string($_POST['campos1']);
if (($_POST[centros]=="cta") AND ($_POST[campos1]=="id"))
{
$query = mysql_query("SELECT * FROM CTA INNER JOIN COMPLEXIONES ON CTA.ID_COMP = COMPLEXIONES.ID_COMP
INNER JOIN PIELES ON CTA.ID_PIEL = PIELES.ID_PIEL
INNER JOIN TIPOSCABELLOS ON CTA.ID_TIPCAB = TIPOSCABELLOS.ID_TIPCAB
WHERE ID_CTA = '$_POST[c_busqueda1]'");

echo "<table border=\"1\" bordercolor=\"#000000\">";
echo "<tr>";
echo "<td bgcolor=\"#FFCC66\"><strong></strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>ID</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Lugar de abordaje</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Lugar de agresion</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Fecha</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Hora</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Lugar de los hechos</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Estatura</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Complexion</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Color de piel</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Tipo de cabello</strong></td>";
echo "</tr>";

while ($registro = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"caja_seleccion\" value=\"Seleccion\"></td>";
echo "<td>$registro[ID_CTA]</td>";
echo "<td>$registro[LABD]</td>";
echo "<td>$registro[LAGR]</td>";
echo "<td>$registro[FECHCTA]</td>";
echo "<td>$registro[HORCTA]</td>";
echo "<td>$registro[LHECS]</td>";
echo "<td>$registro[EST]</td>";
echo "<td>$registro[DESCCOMP]</td>";
echo "<td>$registro[DESCPIEL]</td>";
echo "<td>$registro[DESCTIPCAB]</td>";
}
}

}
?>
</p>
<p>&nbsp; </p>
</form></td>
</tr>

</table>
<table width="139" border="0" align="center">
<tr>
<td width="86"><form name="form2" method="post" action="exportapartado.php">
<input type="submit" name="button" id="button" value="Exportar">
</form> </td>
<td width="70"><form name="form3" method="post" action="">
<input type="submit" name="button2" id="button2" value="Imprimir">
</form>
</td>
</tr>
</table>
<p>&nbsp;</p></TD>
</TR>
</TABLE></th>
</tr>
</table>
</center>
</BODY>
</HTML>



Si nos damos cuenta en la consulta de php mando llamar me control "checkbox" con el name "caja_seleccion" y hasta abajo de la consulta tengo dos botones que es el de exportar
e imprimir pero solo ubiquemonos en el de exportar, entonces cuando yo le doy click en el boton de exportar si me exporta pero todos los registros
y no es eso, sino con el "checkbox" que tengo en la consulta al seleccionarlo me exporte el registro que realmente selecciono.



Aqui dejo mi codigo donde hago la exportacion de todos los registros:



<?php
header("Content-Type: application/vnd.ms-excel");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=Reporte Cta.xls");
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Exportacion Usuarios</title>

</head>

<body topmargin="0" leftmargin="0" bottommargin="0" rightmargin="0">
<?php
include("includes/cnx.php");
if ($_POST['button']=="Exportar")
{
$sql = "SELECT * FROM CTA INNER JOIN COMPLEXIONES ON CTA.ID_COMP = COMPLEXIONES.ID_COMP
INNER JOIN PIELES ON CTA.ID_PIEL = PIELES.ID_PIEL
INNER JOIN TIPOSCABELLOS ON CTA.ID_TIPCAB = TIPOSCABELLOS.ID_TIPCAB";
$result=mysql_query($sql);
echo "<table border = \"1\"><td>ID</td><TD>Lugar de abordaje</TD><TD>Lugar de agresion</TD><TD>Fecha</TD><TD>Hora</TD>
<TD>Lugar de los hechos</TD><TD>Estatura</TD><TD>Complexion</TD><TD>Color de piel</TD>
<TD>Tipo de cabello</TD></table>";
while($reg = mysql_fetch_array($result)) {
printf("<table border = \"1\">
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
<td>&nbsp;%s</td>
</table>",$reg["ID_CTA"],$reg["LABD"],$reg["LAGR"],$reg["FECHCTA"],$reg["HORCTA"],$reg["LHECS"],$reg["EST"],$reg["DESCCOMP"]
,$reg["DESCPIEL"],$reg["DESCTIPCAB"]);
}
mysql_free_result($result);
}
?>
</body>
</html>


Espero me pueda ayudar alguien ya que estoy desesperado por que no encuentro como resolver este problema.
  #2 (permalink)  
Antiguo 17/07/2009, 12:22
Avatar de bng5  
Fecha de Ingreso: junio-2009
Ubicación: 127.0.0.1
Mensajes: 269
Antigüedad: 14 años, 10 meses
Puntos: 24
Respuesta: ¿Como exportar datos a excell usando un checkbox?

Primero que nada olvidate de Micro$soft, exportá a .csv, que el usuario si quiere igual lo puede abrir con Excel.
El código está mal, indicás en la cabecera que es 'Content-Type: application/vnd.ms-excel' pero en el cuerpo enviás un HTML4.

Cambiá el mimetype por 'text/csv' y enviá el cuerpo en ese formato.
  #3 (permalink)  
Antiguo 28/07/2009, 11:12
 
Fecha de Ingreso: septiembre-2003
Mensajes: 182
Antigüedad: 20 años, 7 meses
Puntos: 1
Pregunta Nuevamente como exportar registros usando controles checkbox

Nuevamente sigo con la duda de la exportacion de registros mediante los controles checkbox, el detalle es exportar
todos los registros y que me los generee en un archivo, si no de la consulta que realizo del lado izquierdo aparece una caja de seleccion
osea un "checkbox" y cuando seleccione uno o dos registros o los que sea me exporte esos registro que estoy seleccionando.

Ta realize los cambios para que me exporte en csv.


Aqui pongo primero el codigo de la consulta de mis combos donde seleccionan la opcion para empezar a buscar:

<table width="536" border="0" align="center">
<tr>
<th scope="col"><form name="form1" method="post" action="buscartsocial1.php">
<table width="200" border="0">
<tr>
<td><div align="center" class="style8">Menu de Busquedas</div></td>
</tr>
</table>
<p>
<select name="tablas">
<option>Seleccione la tabla</option>
<option value="expedientes">Expedientes</option>
<option value="victimas">Victimas</option>
<option value="denunciantes">Denunciantes</option>
<option value="generadores">Generadores</option>
</select>
<select name="campos">
<option>Seleccione el campo</option>
<option value="folio">Folio</option>
<option value="nombre">Nombre</option>
</select>
<input type="text" name="c_busqueda">
<input type="submit" name="button" value="Buscar">
</p>
</form></th>
</tr>
<tr>
<th scope="col"><form name="form2" method="post" action="buscarapartados.php">
<select name="centros">
<option>Seleccione el centro</option>
<option value="adevi">ADEVI</option>
<option value="cavi">CAVI</option>
<option value="civa">CIVA</option>
<option value="cta">CTA</option>
<option value="cariva">CARIVA</option>
</select>
<select name="campos1">
<option>Seleccione el campo</option>
<option value="id">ID</option>
</select>
<input type="text" name="c_busqueda1">
<input type="submit" name="button2" id="button" value="Buscar">
</form>
</th>
</tr>
</table>



Aqui dejo ya pego el codigo donde me arroja el resultado la consulta:

<HTML>
<HEAD>
<TITLE>C.I.V.A</TITLE>
</HEAD>
<BODY>

<?php
include("includes/cnx.php");
if (isset($_POST['centros']) AND isset($_POST['campos1']))
{
mysql_real_escape_string($_POST['c_busqueda1']);
mysql_real_escape_string($_POST['centros']);
mysql_real_escape_string($_POST['campos1']);
if (($_POST[centros]=="cta") AND ($_POST[campos1]=="id"))
{
$query = mysql_query("SELECT * FROM CTA WHERE ID_CTA = '$_POST[c_busqueda1]'");

echo "<table border=\"1\" bordercolor=\"#000000\">";
echo "<tr>";
echo "<td bgcolor=\"#FFCC66\"><strong></strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>ID</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Lugar de abordaje</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Lugar de agresion</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Fecha</strong></td>";
echo "<td bgcolor=\"#FFCC66\"><strong>Hora</strong></td>";
echo "</tr>";

while ($registro = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"caja_seleccion\" value=\"Seleccion\"></td>";
echo "<td>$registro[ID_CTA]</td>";
echo "<td>$registro[LABD]</td>";
echo "<td>$registro[LAGR]</td>";
echo "<td>$registro[FECHCTA]</td>";
echo "<td>$registro[HORCTA]</td>";
}
}

}
?>
</p>
<p>&nbsp; </p>
</form></td>
</tr>

</table>
<table width="139" border="0" align="center">
<tr>
<td width="86"><form name="form2" method="post" action="exportapartado.php">
<input type="submit" name="button1" value="Exportar">
</form> </td>
<td width="70"><form name="form3" method="post" action="">
<input type="submit" name="button2" value="Imprimir">
</form>
</td>
</tr>
</table>
<p>&nbsp;</p></TD>
</TR>
</TABLE></th>
</tr>
</table>
</center>
</BODY>
</HTML>


Si nos damos cuenta en la consulta de php mando llamar me control "checkbox" con el name "caja_seleccion" y hasta abajo de la consulta tengo dos botones que es el de exportar
e imprimir pero solo ubiquemonos en el de exportar, entonces cuando yo le doy click en el boton de exportar, si me exporta pero todos los registros
y no es eso, sino con el "checkbox" que tengo en la consulta al seleccionarlo me exporte el registro que realmente selecciono.


Aqui les dejo mi codigo donde hago la exportacion de todos los registros:


<?php
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=cta.csv");

include("includes/cnx.php");
if ($_POST['button1']=="Exportar")
{
$sql = "SELECT * FROM CTA INNER JOIN COMPLEXIONES ON CTA.ID_COMP = COMPLEXIONES.ID_COMP
INNER JOIN PIELES ON CTA.ID_PIEL = PIELES.ID_PIEL
INNER JOIN TIPOSCABELLOS ON CTA.ID_TIPCAB = TIPOSCABELLOS.ID_TIPCAB";
$result=mysql_query($sql);

while ($reg = mysql_fetch_array($result))
{
$registros = $registros.$reg['ID_CTA'].",".$reg['LABD'].",".$reg['LAGR'].",".$reg['FECHCTA'].",".$reg['HORCTA']."\n";
echo $registros;
}
mysql_free_result($result);
}
?>



Espero alguien me pueda orientar.
  #4 (permalink)  
Antiguo 28/07/2009, 13:25
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Nuevamente como exportar registros usando controles checkbox

Temas unidos, porfavor NO dupliques temas.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:13.