title: How to add value in html table column
body: <p>I am working on the following codes. I need to add all the values per category in my table. The data is from the database. Please see the picture first:</p>
  
  <p><a href="https://i.stack.imgur.com/W6pM5.jpg" rel="nofollow noreferrer">Here is my interface image</a></p>
  
  <p>Here is my HTML codes:</p>
  
  <pre><code>&lt;table id="data" class="table table-bordered table-striped"&gt;
              &lt;thead&gt;
              &lt;tr align="center"&gt;
                &lt;th width="5%"&gt;Item&lt;/th&gt;
                &lt;th width="30%"&gt;Description&lt;/th&gt;
                &lt;th width="5%"&gt;Unit&lt;/th&gt;
                &lt;th width="5%"&gt;Qty&lt;/th&gt;
                &lt;th width="10%"&gt;Unit Cost&lt;/th&gt;
                &lt;th width="15%"&gt;Amount&lt;/th&gt;
              &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                &lt;tr&gt;
                  &lt;td&gt;1&lt;/td&gt;
                  &lt;td colspan="5"&gt;&lt;i&gt;General Requirement&lt;/i&gt;&lt;/td&gt;
                &lt;/tr&gt;
  
                &lt;?php  
                $id = $_GET['id'];
                $select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
                $select_bill_result = mysqli_query($con,$select_bill);
                if (mysqli_num_rows($select_bill_result)&gt; 0) {
                  while ($row = mysqli_fetch_assoc($select_bill_result)) {
                    if ($row['category'] == 'General Requirement') {
                ?&gt;
  
                &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['description']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['unit']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['quantity']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['unit_cost']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['amount']; ?&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;?php
                     }
                  }
                }
                ?&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td colspan="4"&gt;&lt;b&gt;Subtotal&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;
                &lt;/tr&gt;
  
                &lt;tr&gt;
                  &lt;td&gt;2&lt;/td&gt;
                  &lt;td colspan="5"&gt;&lt;i&gt;Concrete and Masonry Works&lt;/i&gt;&lt;/td&gt;
                &lt;/tr&gt;
  
                &lt;?php  
                $id = $_GET['id'];
                $select_bill = "SELECT *, quantity * unit_cost AS amount FROM bill_tbl WHERE project_name = $id";
                $select_bill_result = mysqli_query($con,$select_bill);
                if (mysqli_num_rows($select_bill_result)&gt; 0) {
                  while ($row = mysqli_fetch_assoc($select_bill_result)) {
                    if ($row['category'] == 'Concrete and Masonry Works') {
                ?&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['description']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['unit']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['quantity']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['unit_cost']; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $row['amount']; ?&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;?php
                     }
                  }
                }
                ?&gt;
                &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td colspan="4"&gt;&lt;b&gt;Subtotal&lt;/b&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;/td&gt;  
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
  </code></pre>
  
  <p>Script code</p>
  
  <pre><code>&lt;script&gt;  
  var total = 0;
  
  var rows = $("#data tr:gt(0)");
  
  rows.children("td:nth-child(6)").each(function() {
  total += parseInt($(this).html());
  });
  
  $("#total").html(total);
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This is for my school project.</p>