Ver Mensaje Individual
  #12 (permalink)  
Antiguo 28/11/2012, 12:24
Avatar de jandrogdz
jandrogdz
 
Fecha de Ingreso: julio-2012
Ubicación: public $Guadalajara
Mensajes: 397
Antigüedad: 11 años, 10 meses
Puntos: 12
Respuesta: Como llenar un array con formulario

Ya lo solucione

con sesiones lo hice de esta forma no se si sea la mejor forma pero me funciono

Código PHP:
Ver original
  1. <?php
  2. ?>

Código HTML:
Ver original
  1. <form action="" method="post">
  2. <input type="text" name="codigo" />
  3. <input type="text" name="producto" />
  4. <input type="text" name="cantidad" />
  5. <input type="text" name="descripcion" />
  6. <input type="text" name="precioU" />
  7. <input type="submit" name="procesar" />
  8. </form>

Código PHP:
Ver original
  1. <?php
  2. if(isset($_POST["procesar"]))
  3. {
  4.     if(!isset($_SESSION["pedido"]))
  5.     {
  6.         $pedido = $_SESSION["pedido"];
  7.         $pedido[$_POST["codigo"]] = array (
  8.         "codigo"=>$_POST["codigo"],
  9.         "producto"=>$_POST["producto"],
  10.         "cantidad"=>$_POST["cantidad"],
  11.         "descripcion"=>$_POST["descripcion"],
  12.         "precioU"=>$_POST["precioU"]
  13.         );
  14.        
  15.         $_SESSION["pedido"] = $pedido;
  16.     }
  17.     else
  18.     {
  19.         @$pedido = $_SESSION["pedido"];
  20.         $pedido[$_POST["codigo"]] = array (
  21.         "codigo"=>$_POST["codigo"],
  22.         "producto"=>$_POST["producto"],
  23.         "cantidad"=>$_POST["cantidad"],
  24.         "descripcion"=>$_POST["descripcion"],
  25.         "precioU"=>$_POST["precioU"]
  26.         );
  27.        
  28.         $_SESSION["pedido"] = $pedido;
  29.     }
  30.     $total = 0;
  31.     $subtotal = 0;
  32.     ?>
  33.  
  34.     <table border="1" width="700">
  35.         <tr>
  36.             <th>Codigo</th>
  37.             <th>Producto o servicio</th>
  38.             <th>Cantidad</th>
  39.             <th>Descripcion</th>
  40.             <th>$ Precio U.</th>
  41.             <th>$ Importe</th>
  42.         </tr>
  43.     <?php
  44.     foreach($_SESSION["pedido"] as $servicio)
  45.     { $subtotal = $servicio["precioU"] * $servicio["cantidad"]; ?>
  46.  
  47.         <tr>
  48.             <td><?php echo $servicio["codigo"]; ?></td>
  49.             <td><?php echo $servicio["producto"]; ?></td>
  50.             <td><?php echo $servicio["cantidad"]; ?></td>
  51.             <td><?php echo $servicio["descripcion"]; ?></td>
  52.             <td><?php echo $servicio["precioU"]; ?></td>
  53.             <td><?php echo $subtotal; ?></td>
  54.         </tr>
  55.     <?php
  56.     }
  57.     echo "</table>";
  58.     echo  var_dump($_SESSION["pedido"]);
  59.  
  60. }
  61. ?>

y con eso ya me imprime la tabla con los datos de cada arreglo de cada indice y en el var_dump me imprime lo que yo decia

Código PHP:
Ver original
  1.   '001' =>
  2.     array
  3.       'codigo' => string '001' (length=3)
  4.       'producto' => string 'tarjetas' (length=8)
  5.       'cantidad' => string '500' (length=3)
  6.       'descripcion' => string 'tarjetas' (length=8)
  7.       'precioU' => string '1.20' (length=4)
  8.   '002' =>
  9.     array
  10.       'codigo' => string '002' (length=3)
  11.       'producto' => string 'folletos' (length=8)
  12.       'cantidad' => string '1000' (length=4)
  13.       'descripcion' => string 'folletos' (length=8)
  14.       'precioU' => string '50.00' (length=5)
  15.   '003' =>
  16.     array
  17.       'codigo' => string '003' (length=3)
  18.       'producto' => string 'banderas' (length=8)
  19.       'cantidad' => string '500' (length=3)
  20.       'descripcion' => string 'banderas' (length=8)
  21.       'precioU' => string '100' (length=3)
  22.   '004' =>
  23.     array
  24.       'codigo' => string '004' (length=3)
  25.       'producto' => string 'planos' (length=6)
  26.       'cantidad' => string '100' (length=3)
  27.       'descripcion' => string 'planos' (length=6)
  28.       'precioU' => string '50' (length=2)

gracias por el apoyo de todas formas y pateketrueke no te molestes soy novato en esta onda de arreglos y si lei el manual pero no comprendi por eso segui pidiendo apoyo
__________________
Lo imposible solo cuesta un poco mas