Re: array

From: Date: Thu, 04 Apr 2002 18:43:44 +0000
Subject: Re: array
References: 1 2 3  Groups: php.general.es 
Request: Send a blank email to general-es+get-21152@lists.php.net to get a copy of this message
Dijous 04 Abril 2002 19:55, Lizardo Perez Cerpa dixit: > Este es el codigo que saca la cadena: > > $datos=mysql_query("select * from datos where id='$id' order by ip"); > $cant=mysql_num_rows($datos); > $texto="array("; > while ($r=mysql_fetch_array($datos)) > { > > > $texto=$texto.'array(\'asignado\'=>\''.$r[asignado].'\',\'ip\'=>\''.$r[ip]. >' > > \',\'email\'=>\''.$r[email].'\',\'internet\'=>\''.$r[internet].'\',\'instal >a > > cion\'=>\''.$r[instalacion].'\',\'observaciones\'=>\''.$r[observaciones].'\ >' ),'; > // <td>&nbsp;$r[asignado]</td> > // <td>&nbsp;$r[ip]</td> > // <td>&nbsp;$r[email]</td> > // <td>&nbsp;$r[internet]</td> > // <td>&nbsp;$r[instalacion]</td> > // <td>&nbsp;$r[observaciones]</td>"; > } > $texto=$texto.")"; > > como lo modificaria que hacerlo directo a un array Puedes hacerlo así: <? $datos = mysql_query("select * from datos where id='$id' order by ip"); $data = array(); while ($r = mysql_fetch_array($datos)) { $data[] = $r; } ?> Ahora tienes el arreglo en la variable $data: $data[0]['asignado'] será 'aaa' $data[0]['ip'] será '10.10.100.1' .... $data[1]['asignado'] será 'bbb' $data[1]['ip'] será '10.10.100.100' ... etc. Lo puedes hacer incluso un poco un poco más corto, así: <? $datos = mysql_query("select * from datos where id='$id' order by ip"); $data = array(); while ($data[] = mysql_fetch_array($datos)) ; ?> Saludos Àngel

« previous php.general.es (#21152) next »