Re: Array asociativo
| From: | jm aribau | Date: | Fri, 14 Nov 2003 04:11:18 +0000 |
| Subject: | Re: Array asociativo | ||
| References: | 1 2 3 4 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-42599@lists.php.net to get a copy of this message | ||
Aqui tienes el código correcto. El problema radica en el formulario porque los hiddens siempre te
ponen el valor en la variable array. Es mejor quitarlos.
<html>
<body>
<form method="POST">
121 - 1<input type="checkbox" name="cuenta[121][]"
value="1"> <br>
122 - 1<input type="checkbox" name="cuenta[122][]"
value="1"> <br>
121 - 2<input type="checkbox" name="cuenta[121][]"
value="2"> <br>
122 - 2<input type="checkbox" name="cuenta[122][]"
value="2"> <br>
<input type="submit" name="submit"><br>
</form>
<?php
if ($_POST[submit]) { // Si se usa post es mas limpio. Solo GET para
links.
$cuenta = $_POST[cuenta]; // Por si Register_globals = Off
if (is_array($cuenta)) { // Puede ser que no checkeen ninguna opcion
foreach ($cuenta as $key=>$i) {
print('<br>');
foreach ($i as $j) {
echo "Idtit[$key]=$j<br>";
}
}
} else {
print("No hay cuentas seleccionadas");
}
}
?>
</body>
</html>
Josep Ma. Aribau Cano
jm@infodos.com
www.infodos.com
----- Original Message -----
From: "Jorge Vásquez" <jvasquez@smarketing.com.sv>
To: <lista@phpes.com>
Sent: Thursday, November 13, 2003 4:34 PM
Subject: Re: [PHP-ES] Array asociativo
> Hola JM
> Gracias por tu respuesta, pero lastimosamente no funciona :'(, ya habia
> hecho una prueba parecido, el problema es que ni "sizeof" ni "count" me
> dicen realmente el tamaño de $IDtit[$cuenta[$i]], como es un campo oculto y
> no es un campo "checked" entonces no hay forma de saber que $IDtit puede
> valer 1,2 o más.
>
> El resultado que obtuve de lo que tu me dijiste es lo siguiente:
> 121
> 1
> 2
> 2
> 122
> 1
> 2
> 2
> 121
> 1
> 2
> 2
> 122
> 1
> 2
> 2
>
> Que otra forma puede existir de hacerlo que deseo o de que forma puedo
> recorrer lo que mencione antes.
> Gracias por su ayuda.
> Salu2
> Jorge
>
> ----- Original Message -----
> From: "jm aribau" <jm@infodos.com>
> To: <lista@phpes.com>
> Sent: Wednesday, November 12, 2003 10:36 PM
> Subject: Re: [PHP-ES] Array asociativo
>
>
> > for ($i = 0 ; $i < count($cuenta) ; $i++) {
> > echo $cuenta[$i]."<br>";
> > for ($j = 0 ; $j count ($IDtit[$cuenta[$i]]) ; $j++) {
> > echo $IDtit[$cuenta[$i]][$j]."<br>";
> > }
> > }
> >
> > No esta comprovado, hecho on-time.
> >
> > Josep Ma. Aribau Cano
> >
> > ----- Original Message -----
> > From: "Jorge Vásquez" <jvasquez@smarketing.com.sv>
> > To: <lista@phpes.com>
> > Sent: Thursday, November 13, 2003 12:03 AM
> > Subject: Re: [PHP-ES] Array asociativo
> >
> >
> > > Upppppp.. perdon.. habia un error en los checkbox, aqui estan los
> > correctos
> > > <input type="checkbox" name="cuenta[]"
> > > value="121">
> > > <input type="hidden" name="IDtit["121"][]
> > > value="1">
> > > <input type="checkbox" name="cuenta[]"
> > > value="122">
> > > <input type="hidden" name="IDtit["122"][]
> > > value="1">
> > > <input type="checkbox" name="cuenta[]"
> > > value="121">
> > > <input type="hidden" name="IDtit["121"][]
> > > value="2">
> > > <input type="checkbox" name="cuenta[]"
> > > value="122">
> > > <input type="hidden" name="IDtit["122"][]
> > > value="2">
> > >
> > > Para recorrer la cuenta lo hago de la siguiente forma:
> > > for($i=0;$i<sizeof($cuenta);$i++)
> > > {
> > > echo $cuenta[$i]."<br>";
> > > }
> > > El problema resulta cuando quiero recorrer el IDtit, si utilizo $i como
> > > indice no me funciona porque $i vale 4 y el indice de $IDtit es
> solamente
> > 2.
> > >
> > > Gracias por su ayuda.
> > >
> > >
> > > ---------------------------------------------------------------------
> > > Archivo On-line: http://www.phpes.com/
> > > via news: news://news.phpes.com/
> > > Manual PHP en español: http://www.php.net/manual/es/
> > > Para dar de baja la suscripción, mande un mensaje a:
> > > lista-unsubscribe@phpes.com
> >
> >
> > ---------------------------------------------------------------------
> > Archivo On-line: http://www.phpes.com/
> > via news: news://news.phpes.com/
> > Manual PHP en español: http://www.php.net/manual/es/
> > Para dar de baja la suscripción, mande un mensaje a:
> > lista-unsubscribe@phpes.com
> >
>
>
> ---------------------------------------------------------------------
> Archivo On-line: http://www.phpes.com/
> via news: news://news.phpes.com/
> Manual PHP en español: http://www.php.net/manual/es/
> Para dar de baja la suscripción, mande un mensaje a:
> lista-unsubscribe@phpes.com