Ver Mensaje Individual
  #12 (permalink)  
Antiguo 20/04/2014, 23:03
sarrhen
 
Fecha de Ingreso: mayo-2013
Ubicación: San Vicente
Mensajes: 127
Antigüedad: 11 años
Puntos: 1
Respuesta: Sumar la misma variable

aqui de la solucion si se pueden dar cuenta la suma la termino haciendo con una funcion de array_sum, Gracias por el apoyo y por la ayuda dejo el codigo por si otro lo necesita y no pase los apuros que yo pase

Formulario

Código PHP:
Ver original
  1. <?php
  2. if($_POST['concepto']){
  3.  
  4. $concepto[]=$_POST["concepto"];
  5. $valor[]= $_POST["valor"];
  6.  
  7. $lista = array($concepto);
  8.  
  9. for($i=0;$i<count($concepto)-1;$i++){
  10. echo $concepto[$i]."->".$valor[$i]."<br>";
  11. }
  12.  
  13. }
  14. ?>
  15. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  16. <html xmlns="http://www.w3.org/1999/xhtml">
  17. <head>
  18. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  19.  
  20. <meta content="jquery, forumlario dinamico, tutorial" name="keywords"/>
  21.  
  22. <title>Formulario Dinamico</title>
  23. <script type="text/javascript" src="jquery.min.js"></script>
  24. <script type="text/javascript" src="jquery.addfield2.js"></script>
  25.  
  26. <div id="stylized" class="myform" style="margin:20px auto;">
  27.     <form id="form" name="form" method="post" action="procesar.php">
  28.  
  29. <div id="material_comprado"> </div>  
  30.  
  31. <h1>Campos Din&aacute;mico</h1>
  32.  
  33. <label><span class="small">A&ntilde;ade las productos y su valor</span>
  34. </label><br />
  35.     <div id="div_1">
  36.     <label>Producto</label>
  37.         <input  type="text"  name="concepto[]" id="concepto" style="width:200px;" /> <br>
  38.     <label>Valor</label>
  39.         <input  type="text"  name="valor[]" id="valor" style="width:200px;" />
  40.             <input class="bt_plus" id="1" type="button" value="+" /><div class="error_form">
  41.     </div>
  42.    
  43.    
  44. </div>
  45.  
  46. <button type="submit" class="boton">Enviar</button>
  47. <div class="spacer"></div>
  48. </form>

el otro archivo que se llamara procesar

Código PHP:
Ver original
  1. <table border="1" bordercolor="#FFCC00" style="background-color:#FFFFCC" width="100%" cellpadding="3" cellspacing="3">
  2.     <tr>
  3.         <th>concepto</th>
  4.         <th>valor</th>
  5.     </tr>
  6.            
  7.             <?php
  8.  
  9.  
  10. $FirstArray = ($_POST['concepto']);
  11. $SecondArray = ($_POST['valor']);
  12. foreach($FirstArray as $index => $value) {
  13.     echo "<tr>";
  14.         echo "<td>".$FirstArray[$index]."</td>";
  15.            
  16.         echo "<td>".$SecondArray[$index]."</td>";
  17.             echo "</tr>";
  18.  
  19. }
  20.  
  21.  
  22.    echo "<th>Total</th>";
  23.                                 echo "<td>". array_sum($SecondArray) ."</td>";
  24.                                     echo "</tr>";
  25.                                     echo "</table>";
  26. ?>