Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/01/2008, 18:08
pacoalonso79
 
Fecha de Ingreso: agosto-2003
Ubicación: Piura
Mensajes: 238
Antigüedad: 20 años, 8 meses
Puntos: 0
Re: Detalle Factura y Array Dinamico

Hola Patrick:

Yo te recomiendo que en vez de pedirle al usuario que diga cuantos detalles va a agregar solo ponle un boton "agregar detalle" con un solo grupo de cajas de texto vacias para que ponga producto cantidad y precio... luego, al clicar sobre el boton sugerido, guardas los datos posteados en una variable de sesion (un array) y lo vas incrementando automaticamente... algo asi:
Código PHP:
<?php
if (isset($_POST["btnAdd"]))
{
    
// recogemos data posteada por el usuario 
    
$arr1 = array();
    
$arr1["prod"] = $_POST["prod"];
    
$arr1["cant"] = $_POST["cant"];
    
$arr1["prec"] = $_POST["prec"];

    
// agregamos la data posteada al array almacenado en la variable de sesion
    
if (isset($_SESSION["arrDetalles"]))
        
$arrRegs $_SESSION["arrDetalles"];
    else
        
$arrRegs = array();

    
$arrRegs[] = $arr1;
}
?>

<!-- todo el codigo html -->
<form>
<table>
    <tr>
        <td>Producto</td>
        <td>Cantidad</td>
        <td>Precio</td>
    </tr>
<?php
    
for ($i 0$i count($arrRegs); $i++)
    {
        echo 
"<tr>";
        echo 
"<td>".$arrRegs[$i]["prod"]."</td>";
        echo 
"<td>".$arrRegs[$i]["cant"]."</td>";
        echo 
"<td>".$arrRegs[$i]["prec"]."</td>";
        echo 
"</tr>";
    }
?>
    <tr>
        <td><input type="loQueConvenga" name="prod"></td>
        <td><input type="loQueConvenga" name="cant"></td>
        <td><input type="loQueConvenga" name="prec"></td>
        <td><input type="submit" name="btnAdd" value="Agregar Detalle"></td>
    </tr>
</table>
</form>
No se si funcionara el codigo, no lo he probado pero esa es la idea general de mi propuesta...

Muchos éxitos
__________________
Un hombre inteligente, caminando, llega mucho mas rápido que un torpe en coche