Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/08/2009, 23:00
Avatar de gildus
gildus
 
Fecha de Ingreso: agosto-2003
Mensajes: 1.495
Antigüedad: 20 años, 9 meses
Puntos: 105
De acuerdo Respuesta: llenar array() con resultado de query

Holas,

De lo que haces:

Código PHP:
$sQuery = mysql_query("Select PaisId, NombrePais from paises"); 

$paises = mysql_fetch_array($sQuery); 
foreach($paises->result_array() as $row) 

    $first_options = array($row['PaisId'] => $row['NombrePais']); 


<select name="first_select" id="first_select" onchange="test()"> 
        <option value="0"></option> 
        <?php 
        
if (isset($first_options)) 
        { 
            foreach (
$first_options as $key=>$value
            { 
                echo 
'<option value="'.$key.'">'.$value.'</option>'
            } 
        } 
        
?> 
</select>

Podria ser mejor hacerlo asi:

Código PHP:
<?php
$sQuery 
mysql_query("Select PaisId, NombrePais from paises"); 
?>
<select name="first_select" id="first_select" onchange="test()"> 
        <option value="0"></option> 
<?php
while($row mysql_fetch_array($sQuery))
   echo 
'<option value="'.$row['PaisId'].'">'.$row['NombrePais'].'</option>'
?>
</select>
Creo que asi podrias tambien hacerlo en menos codigo y sin mucho bucle.

Saludos
Gildus
__________________
.: Gildus :.