Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/02/2014, 16:53
arros
 
Fecha de Ingreso: noviembre-2009
Mensajes: 535
Antigüedad: 14 años, 6 meses
Puntos: 25
Respuesta: comparar eleccion select multiple y array mostrando los coincidentes

Código PHP:
Ver original
  1. <?php
  2.  
  3. $array1 = array(
  4.     array("NumCuenta" => 2034056, "Nombre" => "Antonio Ruiz", "Saldo" => 1000, "Ciudad" => "Madrid"),
  5.     array("NumCuenta" => 3465748, "Nombre" => "Maria Torres", "Saldo" => 38000, "Ciudad" => "Madrid"),
  6.     array("NumCuenta" => 4768584, "Nombre" => "Javier Vaquero", "Saldo" => 25000, "Ciudad" => "Sevilla"),
  7.     array("NumCuenta" => 4876756, "Nombre" => "Laura Moreno", "Saldo" => 18000, "Ciudad" => "Medina")
  8. );
  9. ?>
  10.  
  11. <form name="form8" method="post" action="">
  12.  
  13.     <h2>Formulario.</h2>    
  14.     <br/>  
  15.     Ciudad: <br/>  
  16.     <select name="ciudades" onchange="this.form.submit()">
  17.         <option value=""> Select </option>
  18.         <option value="Madrid"> Madrid </option>
  19.         <option value="Sevilla"> Sevilla </option>
  20.         <option value="Medina"> Medina </option>
  21.     </select>  
  22.  
  23.     Seleccione para ver el saldo:
  24.     <input type="checkbox" value="saldo" onchange="this.form.submit()" />
  25.  
  26.     <strong>Enviar el formulario.</strong><br/>
  27.     <input type="submit" name="enviar" value="Enviar" />
  28.  
  29. </form>
  30.  
  31. <?php
  32. if (isset($_POST["ciudades"])) {
  33.     $ciudad = $_POST["ciudades"];
  34.     $users = array();
  35.     foreach($array1 as $k=>$v){
  36.         if($ciudad === $array1[$k]["Ciudad"]){
  37.             $users[] = $array1[$k];
  38.         }
  39.     }
  40.     echo "<pre>";
  41.     print_r($users);
  42.     echo "</pre>";
  43. }

se seleccionas Madrid el resultado seria:
Código PHP:
Ver original
  1. (
  2.     [0] => Array
  3.         (
  4.             [NumCuenta] => 2034056
  5.             [Nombre] => Antonio Ruiz
  6.             [Saldo] => 1000
  7.             [Ciudad] => Madrid
  8.         )
  9.  
  10.     [1] => Array
  11.         (
  12.             [NumCuenta] => 3465748
  13.             [Nombre] => Maria Torres
  14.             [Saldo] => 38000
  15.             [Ciudad] => Madrid
  16.         )
  17.  
  18. )
__________________
cada vez que aprendes algo te crees que no sabes nada