Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/07/2009, 11:03
crucifijo
 
Fecha de Ingreso: septiembre-2003
Mensajes: 182
Antigüedad: 20 años, 8 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.