elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  problema combo box
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: problema combo box  (Leído 1,416 veces)
kakashi20


Desconectado Desconectado

Mensajes: 435


Ver Perfil
problema combo box
« en: 6 Marzo 2012, 02:22 am »

hola

tengo este codigo el cual trae un srting de hora asi: 14:00:00 y con un split divide la cadena en tres. el problema es que solo me esta mostrando el segundo combobox y no me muestra el primero

   $hora_cadena=split(":",$row[hora_fin]);
                  
                  
                  
               echo "<td>   
                  <select id='hf".$row[id]."' name='hf".$row[id]."''><option value='00'>H</option>
                  
                           ";if ( $hora_cadena[0] == "01" ) { echo "<option value='01' selected='selected'>01</option>"; }else { echo "<option value='01'>01</option>"; }"
                           ";if ( $hora_cadena[0] == "02" ) { echo "<option value='02' selected='selected'>02</option>"; }else { echo "<option value='02'>02</option>"; }"
                           ";if ( $hora_cadena[0] == "03" ) { echo "<option value='03' selected='selected'>03</option>"; }else { echo "<option value='03'>03</option>"; }"
                           ";if ( $hora_cadena[0] == "04" ) { echo "<option value='04' selected='selected'>04</option>"; }else { echo "<option value='04'>04</option>"; }"
                           ";if ( $hora_cadena[0] == "05" ) { echo "<option value='05' selected='selected'>05</option>"; }else { echo "<option value='05'>05</option>"; }"
                           ";if ( $hora_cadena[0] == "06" ) { echo "<option value='06' selected='selected'>06</option>"; }else { echo "<option value='06'>06</option>"; }"
                           ";if ( $hora_cadena[0] == "07" ) { echo "<option value='07' selected='selected'>07</option>"; }else { echo "<option value='07'>07</option>"; }"
                           ";if ( $hora_cadena[0] == "08" ) { echo "<option value='08' selected='selected'>08</option>"; }else { echo "<option value='08'>08</option>"; }"
                           ";if ( $hora_cadena[0] == "09" ) { echo "<option value='09' selected='selected'>09</option>"; }else { echo "<option value='09'>09</option>"; }"
                           ";if ( $hora_cadena[0] == "10" ) { echo "<option value='10' selected='selected'>10</option>"; }else { echo "<option value='10'>10</option>"; }"
                           ";if ( $hora_cadena[0] == "11" ) { echo "<option value='11' selected='selected'>11</option>"; }else { echo "<option value='11'>11</option>"; }"
                           ";if ( $hora_cadena[0] == "12" ) { echo "<option value='12' selected='selected'>12</option>"; }else { echo "<option value='12'>12</option>"; }"
                           ";if ( $hora_cadena[0] == "13" ) { echo "<option value='13' selected='selected'>13</option>"; }else { echo "<option value='13'>13</option>"; }"
                           ";if ( $hora_cadena[0] == "14" ) { echo "<option value='14' selected='selected'>14</option>"; }else { echo "<option value='14'>14</option>"; }"
                           ";if ( $hora_cadena[0] == "15" ) { echo "<option value='15' selected='selected'>15</option>"; }else { echo "<option value='15'>15</option>"; }"
                           ";if ( $hora_cadena[0] == "16" ) { echo "<option value='16' selected='selected'>16</option>"; }else { echo "<option value='16'>16</option>"; }"
                           ";if ( $hora_cadena[0] == "17" ) { echo "<option value='17' selected='selected'>17</option>"; }else { echo "<option value='17'>17</option>"; }"
                           ";if ( $hora_cadena[0] == "18" ) { echo "<option value='18' selected='selected'>18</option>"; }else { echo "<option value='18'>18</option>"; }"
                           ";if ( $hora_cadena[0] == "19" ) { echo "<option value='19' selected='selected'>19</option>"; }else { echo "<option value='19'>19</option>"; }"
                           ";if ( $hora_cadena[0] == "20" ) { echo "<option value='20' selected='selected'>20</option>"; }else { echo "<option value='20'>20</option>"; }"
                           ";if ( $hora_cadena[0] == "21" ) { echo "<option value='21' selected='selected'>21</option>"; }else { echo "<option value='21'>21</option>"; }"
                           ";if ( $hora_cadena[0] == "22" ) { echo "<option value='22' selected='selected'>22</option>"; }else { echo "<option value='22'>22</option>"; }"
                           ";if ( $hora_cadena[0] == "23" ) { echo "<option value='23' selected='selected'>23</option>"; }else { echo "<option value='23'>23</option>"; }"
                           
                           
                           
                           
                     </select>-<select id='mf".$row[id]."' name='mf".$row[id]."''><option value='00'>M</option>
                           
                           ";if ( $hora_cadena[1] == "01" ) { echo "<option value='01' selected='selected'>01</option>"; }else { echo "<option value='01'>01</option>"; }"
                           ";if ( $hora_cadena[1] == "02" ) { echo "<option value='02' selected='selected'>02</option>"; }else { echo "<option value='02'>02</option>"; }"
                           ";if ( $hora_cadena[1] == "03" ) { echo "<option value='03' selected='selected'>03</option>"; }else { echo "<option value='03'>03</option>"; }"
                           ";if ( $hora_cadena[1] == "04" ) { echo "<option value='04' selected='selected'>04</option>"; }else { echo "<option value='04'>04</option>"; }"
                           ";if ( $hora_cadena[1] == "05" ) { echo "<option value='05' selected='selected'>05</option>"; }else { echo "<option value='05'>05</option>"; }"
                           ";if ( $hora_cadena[1] == "06" ) { echo "<option value='06' selected='selected'>06</option>"; }else { echo "<option value='06'>06</option>"; }"
                           ";if ( $hora_cadena[1] == "07" ) { echo "<option value='07' selected='selected'>07</option>"; }else { echo "<option value='07'>07</option>"; }"
                           ";if ( $hora_cadena[1] == "08" ) { echo "<option value='08' selected='selected'>08</option>"; }else { echo "<option value='08'>08</option>"; }"
                           ";if ( $hora_cadena[1] == "09" ) { echo "<option value='09' selected='selected'>09</option>"; }else { echo "<option value='09'>09</option>"; }"
                           ";if ( $hora_cadena[1] == "10" ) { echo "<option value='10' selected='selected'>10</option>"; }else { echo "<option value='10'>10</option>"; }"
                           ";if ( $hora_cadena[1] == "11" ) { echo "<option value='11' selected='selected'>11</option>"; }else { echo "<option value='11'>11</option>"; }"
                           ";if ( $hora_cadena[1] == "12" ) { echo "<option value='12' selected='selected'>12</option>"; }else { echo "<option value='12'>12</option>"; }"
                           ";if ( $hora_cadena[1] == "13" ) { echo "<option value='13' selected='selected'>13</option>"; }else { echo "<option value='13'>13</option>"; }"
                           ";if ( $hora_cadena[1] == "14" ) { echo "<option value='14' selected='selected'>14</option>"; }else { echo "<option value='14'>14</option>"; }"
                           ";if ( $hora_cadena[1] == "15" ) { echo "<option value='15' selected='selected'>15</option>"; }else { echo "<option value='15'>15</option>"; }"
                           ";if ( $hora_cadena[1] == "16" ) { echo "<option value='16' selected='selected'>16</option>"; }else { echo "<option value='16'>16</option>"; }"
                           ";if ( $hora_cadena[1] == "17" ) { echo "<option value='17' selected='selected'>17</option>"; }else { echo "<option value='17'>17</option>"; }"
                           ";if ( $hora_cadena[1] == "18" ) { echo "<option value='18' selected='selected'>18</option>"; }else { echo "<option value='18'>18</option>"; }"
                           ";if ( $hora_cadena[1] == "19" ) { echo "<option value='19' selected='selected'>19</option>"; }else { echo "<option value='19'>19</option>"; }"
                           ";if ( $hora_cadena[1] == "20" ) { echo "<option value='20' selected='selected'>20</option>"; }else { echo "<option value='20'>20</option>"; }"
                           ";if ( $hora_cadena[1] == "21" ) { echo "<option value='21' selected='selected'>21</option>"; }else { echo "<option value='21'>21</option>"; }"
                           ";if ( $hora_cadena[1] == "22" ) { echo "<option value='22' selected='selected'>22</option>"; }else { echo "<option value='22'>22</option>"; }"
                           ";if ( $hora_cadena[1] == "23" ) { echo "<option value='23' selected='selected'>23</option>"; }else { echo "<option value='23'>23</option>"; }"
                           ";if ( $hora_cadena[1] == "24" ) { echo "<option value='24' selected='selected'>24</option>"; }else { echo "<option value='24'>24</option>"; }"
                           ";if ( $hora_cadena[1] == "25" ) { echo "<option value='25' selected='selected'>25</option>"; }else { echo "<option value='25'>25</option>"; }"
                           ";if ( $hora_cadena[1] == "26" ) { echo "<option value='26' selected='selected'>26</option>"; }else { echo "<option value='26'>26</option>"; }"

                           ";if ( $hora_cadena[1] == "27" ) { echo "<option value='27' selected='selected'>27</option>"; }else { echo "<option value='27'>27</option>"; }"
                           ";if ( $hora_cadena[1] == "28" ) { echo "<option value='28' selected='selected'>28</option>"; }else { echo "<option value='28'>28</option>"; }"
                           ";if ( $hora_cadena[1] == "29" ) { echo "<option value='29' selected='selected'>29</option>"; }else { echo "<option value='29'>29</option>"; }"
                           ";if ( $hora_cadena[1] == "30" ) { echo "<option value='30' selected='selected'>30</option>"; }else { echo "<option value='30'>30</option>"; }"
                           ";if ( $hora_cadena[1] == "31" ) { echo "<option value='31' selected='selected'>31</option>"; }else { echo "<option value='31'>31</option>"; }"
                           ";if ( $hora_cadena[1] == "32" ) { echo "<option value='32' selected='selected'>32</option>"; }else { echo "<option value='32'>32</option>"; }"
                           ";if ( $hora_cadena[1] == "33" ) { echo "<option value='33' selected='selected'>33</option>"; }else { echo "<option value='33'>33</option>"; }"
                           ";if ( $hora_cadena[1] == "34" ) { echo "<option value='34' selected='selected'>34</option>"; }else { echo "<option value='34'>34</option>"; }"
                           ";if ( $hora_cadena[1] == "35" ) { echo "<option value='35' selected='selected'>35</option>"; }else { echo "<option value='35'>35</option>"; }"
                           ";if ( $hora_cadena[1] == "36" ) { echo "<option value='36' selected='selected'>36</option>"; }else { echo "<option value='36'>36</option>"; }"
                           ";if ( $hora_cadena[1] == "37" ) { echo "<option value='37' selected='selected'>37</option>"; }else { echo "<option value='37'>37</option>"; }"
                           ";if ( $hora_cadena[1] == "38" ) { echo "<option value='38' selected='selected'>38</option>"; }else { echo "<option value='38'>38</option>"; }"
                           ";if ( $hora_cadena[1] == "39" ) { echo "<option value='39' selected='selected'>39</option>"; }else { echo "<option value='39'>39</option>"; }"
                           ";if ( $hora_cadena[1] == "40" ) { echo "<option value='40' selected='selected'>40</option>"; }else { echo "<option value='40'>40</option>"; }"
                           ";if ( $hora_cadena[1] == "41" ) { echo "<option value='41' selected='selected'>41</option>"; }else { echo "<option value='41'>41</option>"; }"
                           ";if ( $hora_cadena[1] == "42" ) { echo "<option value='42' selected='selected'>42</option>"; }else { echo "<option value='42'>42</option>"; }"
                           ";if ( $hora_cadena[1] == "43" ) { echo "<option value='43' selected='selected'>43</option>"; }else { echo "<option value='43'>43</option>"; }"
                           ";if ( $hora_cadena[1] == "44" ) { echo "<option value='44' selected='selected'>44</option>"; }else { echo "<option value='44'>44</option>"; }"
                           ";if ( $hora_cadena[1] == "45" ) { echo "<option value='45' selected='selected'>45</option>"; }else { echo "<option value='45'>45</option>"; }"
                           ";if ( $hora_cadena[1] == "46" ) { echo "<option value='46' selected='selected'>46</option>"; }else { echo "<option value='46'>46</option>"; }"
                           ";if ( $hora_cadena[1] == "47" ) { echo "<option value='47' selected='selected'>47</option>"; }else { echo "<option value='47'>47</option>"; }"
                           ";if ( $hora_cadena[1] == "48" ) { echo "<option value='48' selected='selected'>48</option>"; }else { echo "<option value='48'>48</option>"; }"
                           ";if ( $hora_cadena[1] == "49" ) { echo "<option value='49' selected='selected'>49</option>"; }else { echo "<option value='49'>49</option>"; }"
                           ";if ( $hora_cadena[1] == "50" ) { echo "<option value='50' selected='selected'>50</option>"; }else { echo "<option value='50'>50</option>"; }"
                           ";if ( $hora_cadena[1] == "51" ) { echo "<option value='51' selected='selected'>51</option>"; }else { echo "<option value='51'>51</option>"; }"
                           ";if ( $hora_cadena[1] == "52" ) { echo "<option value='52' selected='selected'>52</option>"; }else { echo "<option value='52'>52</option>"; }"
                           ";if ( $hora_cadena[1] == "53" ) { echo "<option value='53' selected='selected'>53</option>"; }else { echo "<option value='53'>53</option>"; }"
                           ";if ( $hora_cadena[1] == "54" ) { echo "<option value='54' selected='selected'>54</option>"; }else { echo "<option value='54'>54</option>"; }"
                           ";if ( $hora_cadena[1] == "55" ) { echo "<option value='55' selected='selected'>55</option>"; }else { echo "<option value='55'>55</option>"; }"
                           ";if ( $hora_cadena[1] == "56" ) { echo "<option value='56' selected='selected'>56</option>"; }else { echo "<option value='56'>56</option>"; }"
                           ";if ( $hora_cadena[1] == "57" ) { echo "<option value='57' selected='selected'>57</option>"; }else { echo "<option value='57'>57</option>"; }"
                           ";if ( $hora_cadena[1] == "58" ) { echo "<option value='58' selected='selected'>58</option>"; }else { echo "<option value='58'>58</option>"; }"
                           ";if ( $hora_cadena[1] == "59" ) { echo "<option value='59' selected='selected'>59</option>"; }else { echo "<option value='59'>59</option>"; }"
                           
                        </select>
                     
                     
                  </td>";

Si alguien me pudiese ayudar se lo agradeceria


En línea

cassiani


Desconectado Desconectado

Mensajes: 978


« Anterior | Próximo »


Ver Perfil WWW
Re: problema combo box
« Respuesta #1 en: 10 Marzo 2012, 19:07 pm »

las comillas en el array $row junto con la cadena dentro de los corchetes, identifican al elemento del array.

Cuando ves que una instrucción se repite más de una vez, usa ciclos/loops para simplificar el código, ejemplo:

Código
  1. <?php
  2. $row['hora_fin'] = "06:25";
  3. $row['id'] = 6;
  4. $hora_cadena=explode(":",$row['hora_fin']);
  5.  
  6. echo '<td><select id="hf',$row['id'],'" name="hf',$row['id'],'" >
  7.   <option value="00">H</option>';
  8.  
  9. for($i=1; $i<=23 ;$i++){        
  10.  
  11.    echo  ($hora_cadena[0] == $i
  12.    ? "<option value='$i' selected='selected'>$i</option>"  
  13.    : "<option value='$i'>$i</option>");                
  14. }                
  15.  
  16. echo '</select>-<select id="mf',$row['id'],'" name="mf',$row['id'],'" >
  17.   <option value="00">M</option>';
  18.  
  19. for($i=1; $i<=59 ;$i++){        
  20.  
  21.    echo  ($hora_cadena[1] == $i
  22.    ? "<option value='$i' selected='selected'>$i</option>"
  23.    : "<option value='$i'>$i</option>");                
  24. }                
  25. echo '</select></td>';

También use el operador ternario.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problemas con combo dvd
Software
Ferchu 1 1,611 Último mensaje 23 Enero 2004, 19:14 pm
por Songoku
grabadora combo?
Software
kriptiko 3 2,371 Último mensaje 15 Mayo 2004, 08:44 am
por malferI
COMBO que no graba ni lee CD
Software
Stevan 1 2,149 Último mensaje 3 Diciembre 2004, 03:58 am
por el-brujo
problema al grabar a mas de 4x en combo LG
Software
k a t z 0 1,347 Último mensaje 24 Octubre 2005, 21:07 pm
por k a t z
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines