title: JavaScript loop does not calculate / show result properly
body: <pre><code>$(document).ready(function () {
  
      //$('#customer_info #next_step').click(function() {
  
      $.getJSON("order/summary_process2.php?jsoncallback=?", function (data) {
  
          //loop through all items in the JSON array
          for (var x = 0; x &lt; data.length; x++) {
  
              //create a container for each comment
              var div = $("&lt;tr&gt;").addClass("row").appendTo("#row");
  
              //add author name and comment to container
              $("&lt;td&gt;").addClass("space").text(data[x].item_name).appendTo(div);
              $("&lt;td&gt;").addClass("space").text(data[x].price).appendTo(div);
              $("&lt;td&gt;").addClass("space").text(data[x].qty).appendTo(div);
              $("&lt;td&gt;").addClass("space").text(data[x].tot_price).appendTo(div);
              //$("&lt;div&gt;").addClass("comment").text(data[x].comment).appendTo(div);
  
          }
  
          for (var i = 0; i &lt; data.length; i++) {
              var total = 0;
              total = data[i].tot_price + total;
          }
          $("#total").html(total);
  
      });
  });
  //});
  });
  </code></pre>
  
  <p>I'm using <code>JSON</code>, but I want to add the total price.</p>
  
  <p>Unfortunately, the result is wrong.</p>