Ver Mensaje Individual
  #4 (permalink)  
Antiguo 16/09/2018, 19:14
Avatar de hhs
hhs
Colaborador
 
Fecha de Ingreso: junio-2013
Ubicación: México
Mensajes: 2.995
Antigüedad: 10 años, 9 meses
Puntos: 379
Respuesta: Seleccionar opción de dropdown con base en un $_POST

Utiliza la sintaxis alternativa e itera con un foreach
Código PHP:
Ver original
  1. //Formulario
  2. <select name="year">
  3.    
  4.     <?php foreach(range(2000, 2010) as $year): ?>
  5.    
  6.         <option value="<?php echo $year?>">
  7.             <?php echo $year?>
  8.         </option>
  9.        
  10.     <?php endforeach; ?>
  11.    
  12. </select>
  13.  
  14. //recibes datos
  15. <?php $_POST['year'] = 2005; ?>
  16.  
  17. //vuelves a crear el select
  18. <select name="year">
  19.    
  20.     <?php foreach(range(2000, 2010) as $year): ?>
  21.        
  22.             <option value="<?php echo $year?>"<?php if($year == $_POST['year']) echo ' selected'?>>
  23.                 <?php echo $year ?>
  24.             </option>
  25.            
  26.     <?php endforeach; ?>
  27.    
  28. </select>
__________________
Saludos
About me
Laraveles
A class should have only one reason to change.