Foros del Web » Programando para Internet » PHP »

Problemas CheckBox

Estas en el tema de Problemas CheckBox en el foro de PHP en Foros del Web. El tema es el siguiente tengo una lista con diferentes elementos y a su vez cada elemento tiene su checkbox yo quiero que al seleccionar ...
  #1 (permalink)  
Antiguo 07/01/2009, 07:29
 
Fecha de Ingreso: abril-2007
Mensajes: 1
Antigüedad: 17 años
Puntos: 0
Problemas CheckBox

El tema es el siguiente tengo una lista con diferentes elementos y a su vez cada elemento tiene su checkbox yo quiero que al seleccionar cada checkbox me haga un update de estado=1 en la bd de los elementos que elegi de los checkbox no se si me explico paso a poner una foto


http://img101.imageshack.us/my.php?image=checkboxcy9.jpg

MI CODIGO

pro-rrhh03.php

<!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=utf-8" />
<title>Alta Empleado</title>
<script>
// definimos los bloques
OCULTO="none";
VISIBLE="block";

function mostrar(blo) {
document.getElementById(blo).style.display=VISIBLE ;
document.getElementById('ver_off').style.display=V ISIBLE;
document.getElementById('ver_on').style.display=OC ULTO;
}

function ocultar(blo) {
document.getElementById(blo).style.display=OCULTO;
document.getElementById('ver_off').style.display=O CULTO;
document.getElementById('ver_on').style.display=VI SIBLE;
}
</script>

</head>

<body>
<div>
<form name="result" action="procesarSeleccion.php" method="get">

<p>
<?php

// creo función para conectar con DB
include('config.php');
$link=Conectarse();
extract($_GET);

// Almaceno en variables los datos del form

$idempleado=$_GET['rad'];
print("<input type=\"hidden\" name=\"idemp\" value=$idempleado />");

// Genero una variable con la consulta deseada
$result=mysql_query("SELECT *
FROM empleados
WHERE id=$idempleado",
$link);

while($row = mysql_fetch_array($result)) {
printf("&nbsp;Empleado: %s %s &nbsp; <br>&nbsp;Fecha de Ingreso (AAAA-MM-DD): %s &nbsp; <br><br>",
$row["nombre"],
$row["apellido"],
$row["f_ingreso"]);
}

//Libero la memoria
mysql_free_result($result);

?>
<span>Herramientas</span>
</p>
<p><span>Desktop</span> </p>

<div id="ver_on"><input name="Kits" type="button" value="Ver Kits" onclick="mostrar('bloque')" />
</div>
<div id="ver_off" style="display: none"><input name="Kits" type="button" value=" Ocultar Kits" onclick="ocultar('bloque')" /></div>
<div id="bloque" style="display: none">

<table width="651">
<tr bgcolor="#666666" align="center"><td width="168">&nbsp;Proveedor</td><td width="144">&nbsp;Marca</td><td width="149">&nbsp;Modelo</td><td width="140">&nbsp;Especificaciones</td></tr>
<?php

// Cargo la tabla
$result2=mysql_query("SELECT u.id_utilitarios, p.nombre, u.marca_d,u.modelo_d,u.especificaciones_d
FROM proveedores p, utilitarios u, tipoUtilitario tu
WHERE p.id=u.id_proveedor and u.id_tipoutilitario=tu.id_tipoutilitario
and u.estado=0 and tu.tipo='desktop'
ORDER BY u.marca_d",
$link);
$i=0;
while($row2 = mysql_fetch_array($result2)) {

printf("<tr><td class='ContResult'>&nbsp;%s</td>
<td class='ContResult'>&nbsp;%s</td>
<td class='ContResult'>&nbsp;%s</td>
<td class='ContResult'>&nbsp;%s</td>",
$row2["nombre"],
$row2["marca_d"],
$row2["modelo_d"],
$row2["especificaciones_d"]);

printf("<td class='ContResult'>&nbsp;<input type=\"checkbox\" value=\"%d\" name=\"seleccion[%d]\" />&nbsp;</td></tr>",$row2[0],$i);
$i++;
}

//Libero la memoria
mysql_free_result($result2);

// Cierro la conexión
mysql_close($link);
?>
</table>
</div>
<p>&nbsp;</p>
<p>
<input value="Aceptar Selección" type="submit" />
</p>
</form>
</div>
</body>
</html>

procesarSeleccion.php
<!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=utf-8" />
<title>Documento sin título</title>
</head>
<?php
//incluir conexión a la bdd
include('config.php');
$link=Conectarse();
extract($_GET);

$cont=$_GET[$i];
printf("%d",$cont);

for($t=0;$t<=$cont;$t++)
{
$id=$_GET[$seleccion[$t]];
printf("%d",$id);
$res=mysql_query("UPDATE utilitarios SET estado=1 where id_utilitarios=$id",$link);
}

?>
<body>
</body>
</html>


Les agradezco la ayuda desde ya a todos

Última edición por yango18; 07/01/2009 a las 08:38
  #2 (permalink)  
Antiguo 07/01/2009, 15:24
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Problemas CheckBox

Visita el subforo de AJAX, ahi es mas facil obtener respuesta a lo que necesitas.
__________________
- León, Guanajuato
- GV-Foto
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 09:25.