Ver Mensaje Individual
  #5 (permalink)  
Antiguo 24/04/2013, 03:21
pr0
 
Fecha de Ingreso: marzo-2004
Mensajes: 687
Antigüedad: 20 años, 1 mes
Puntos: 28
Respuesta: Simplificar código, post

Código PHP:
Ver original
  1. for($i = 0; $i <= 50; $i++){
  2.    
  3.    $cantidad = $_POST['cant'.$i.'c'];
  4.    $precio = $_POST ['prec'.$i.'c'];
  5.    $res = $_POST['res'.$i.'c'];
  6.  
  7.    if($cantidad != 0)
  8.       echo $cantidad. " - Producto 1 a: " . "\$" . $precio . " -- Subtotal = $" . $res. " \n " . "<br>";
  9.  
  10. }

Te recomendaría que los campos del formulario tuvieran un nombre más "limpio", en lugar de 'cant1c' llamarlos cantidad1 así luego quedaría mejor poner $_POST['cantidad'.$i];