Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/07/2011, 18:56
Avatar de kimmy
kimmy
 
Fecha de Ingreso: julio-2008
Mensajes: 841
Antigüedad: 15 años, 9 meses
Puntos: 15
Mostrar valores de textbox seleccionados

Hola:

Tengo un problema con esto. Yo tengo un form que recolecta una cantidad de opciones que puede seleccionar el cliente a través de checkbox y su respectiva caja de texto para colocar la cantidad. Lo que seleccione se guarda en una variable de sesion y al final debo mostrar cuales opciones eligio de check y de textbox. Este es el form donde coloca los datos que se alimenta de una bd:

Código PHP:
Ver original
  1. <form name="form3" action="cotizacion.php?page=cotizacion_3" method="post">
  2. <table width="600">
  3.   <tr>
  4.     <td width="300">
  5.  
  6.  <table width="300">
  7.  <tr>
  8. <th colspan="3"><center>Alimentos</center></th>
  9. </tr>
  10. <?php echo "
  11.  <td width=\"150\">Producto</td>
  12.  <td width=\"100\">Seleccionar</td>  
  13.  <td width=\"150\">Cantidad</td>  
  14.  </tr>
  15.  <tr>";
  16.     $rs = mysql_query("SELECT * FROM xxxx where categoria='alimentos'");
  17.     while ($result = mysql_fetch_array($rs)) {
  18.     $categoria = $result['categoria'];
  19.     $alim = $result['alim'];
  20. echo
  21. "          
  22.   <td>$producto_alim</td>
  23.   <td><input name=\"alimentos[]\" type=\"checkbox\" value=\"$alim\"></td>
  24.   <td><input name=\"ctdad_alimentos[]\" type=\"text\" value=\"\" size=\"3\"></td>    
  25.   </tr>"; }?>
  26.     </table>
  27.  
  28. <td width="300"><table width="300">
  29. <tr>
  30. <th colspan="3"><center>Bebidas</center></th>
  31. </tr>
  32. <?php echo
  33. "
  34.  <tr>
  35.  <td width=\"150\">Producto</td>
  36.  <td width=\"100\">Seleccionar</td>  
  37.  <td width=\"150\">Cantidad</td>  
  38.  </tr>
  39.  <tr>";
  40.     $rs = mysql_query("SELECT * FROM xxxxxx where categoria='bebidas'");
  41.     while ($result = mysql_fetch_array($rs)) {
  42.     $categoria = $result['categoria'];
  43.     $bebidas = $result['producto'];
  44. echo
  45. "          
  46.   <td>$producto_bebidas</td>
  47.   <td><input name=\"bebidas[]\" type=\"checkbox\" value=\"$bebidas\"></td>
  48.   <td><input name=\"ctdad_bebidas[]\" type=\"text\" value=\"\" size=\"3\"></td>    
  49.   </tr>
  50.  ";
  51. }
  52. ?>
  53.     </table></td></td>
  54.   </tr>
  55. </table>
  56. <label>
  57.     <p align="center">
  58.     <input name="regresar" type="button" value="Atras" onclick="location.href='cotizacion.php?page=cotizacion_1'">
  59.     <input name="siguiente" type="submit" value="Siguiente">
  60.         <input name="salir" type="button" value="Salir" onclick="location.href='index2.php'">
  61.     </p>
  62.    </label>
  63. </form>

y en este otro muestro lo recolectado con $_SESSION['variables1']=$_POST;:

Código PHP:
Ver original
  1. <tr>
  2.    <td>Alimentos</td>
  3.    <td><?php
  4.    if (isset($_SESSION['variables1']['alimentos'])) {
  5. foreach($_SESSION['variables1']['alimentos'] as $v)
  6.   {
  7.     echo "<input name=\"alimentos\" value=\"$v\" readonly=\"readonly\">";  
  8.    echo "<br>";
  9.   }
  10.    }
  11.   else {
  12.        echo "No hay Datos";}
  13. ?> </td>
  14. <td>Cantidad:</td>
  15. <td>
  16.    <?php
  17.       if (isset($_SESSION['variables1']['ctdad_alimentos'])) {
  18.  
  19.  foreach($_SESSION['variables1']['ctdad_alimentos'] as $v)
  20.   {
  21.     echo "<input name=\"ctdad_alimentos\" value=\"$v\" readonly=\"readonly\">";  
  22.    echo "<br>";
  23.   }}
  24.    else {
  25.        echo "No hay Datos";
  26.        }
  27. ?></td>
  28.  </tr>  
  29.  <tr>  
  30.    <td>Bebidas</td>
  31.    <td><?php
  32.    if (isset($_SESSION['variables2']['bebidas'])) {
  33.  foreach($_SESSION['variables2']['bebidas'] as $v)
  34.   {
  35.     echo "<input name=\"bebidas[]\" value=\"$v\" readonly=\"readonly\">";  
  36.    echo "<br>";
  37.   }
  38.    }
  39.    else {
  40.        echo "No hay Datos";
  41.        }
  42. ?></td>

El problema es que como existen 20 categorias de bebidas por ejemplo al mostrar la cantidad me trae todos los input text y no los que el cliente seleccionó.

He probado de distintas formas pero no se como arreglar esto.

Por favor pueden darme una ayudita para entender. Gracias.
__________________
Caminando con el corazón partío