-1

表示されたテーブルの列を合計する必要があります。私の質問:他の列からデータを計算したテーブル列を合計するにはどうすればよいですか?それを行うにはJavaScriptを使用する必要がありますか?関連する列の下部に合計を表示したいと思います。よろしくお願いします。

私の現在の計算データの例:

echo round(($r->price_sold - $r->shipping - $r->tax - $r->fees) * $r->commission_rate / 100,2);



    $query = "
SELECT *
  FROM jos_data_Used_Gear
  ORDER BY client_name ASC  
  LIMIT 0, 100;
";

$db->setQuery($query);
$url = $db->loadObjectList();


echo '<table id="consignment-table" border="0" align="center" width="3000px">'; 
echo '<tr class="consignment-header"><th class="consignment-client">Client</th>'; 
echo '<th class="consignment-title">Item Name</th>'; 
echo '<th class="consignment-saleprice">Price Sold</th>'; 
echo '<th class="consignment-saleprice">Tax</th>';
echo '<th class="consignment-saleprice">Shipping</th>';
echo '<th class="consignment-saleprice">Service Fee</th>';
echo '<th class="consignment-saleprice">Commission</th>';
echo '<th class="consignment-saleprice">Due Client</th>'; 

if(count($url)) {
  foreach($url as $r) {
    echo '<tr><td nowrap="nowrap">';
    echo $r->client_name;
    echo '</td><td nowrap="nowrap">'; 
    echo $r->item_title;
    echo '</td><td class="currency" nowrap="nowrap">'; 
    echo "&#36;";
    echo $r->price_sold;
    echo '</td><td nowrap="nowrap">'; 
    echo "&#36;";
    echo $r->tax;
    echo '</td><td class="currency" nowrap="nowrap">'; 
    echo "&#36;";
    echo $r->shipping;
    echo '</td><td nowrap="nowrap">'; 
    echo "&#36;";
    echo $r->fees;
    echo '</td><td nowrap="nowrap">'; 
    echo round(($r->price_sold - $r->shipping - $r->tax - $r->fees) * $r->commission_rate / 100,2);
    echo '</td><td class="currency" nowrap="nowrap">'; 
    echo "&#36;";
    echo round(($r->price_sold - $r->fees - $r->tax - $r->shipping) - (($r->price_sold - $r->fees - $r->tax - $r->shipping) * $r->commission_rate / 100) ,2);
    echo "</td></tr>";

  } 
}

echo '</table>';
4

1 に答える 1

1

http://jsbin.com/opevet/1/edit

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<table id="consignment-table" border="1" align="center" width="500px">
<tr class="consignment-header"><th class="consignment-client">Client</th>
<th class="consignment-title">Item Name</th>
<th class="consignment-saleprice">Price Sold</th>
<th class="consignment-saleprice">Tax</th>
<th class="consignment-saleprice">Shipping</th>
<th class="consignment-saleprice">Service Fee</th>
<th class="consignment-saleprice">Commission</th>
<th class="consignment-saleprice">Due Client</th>
    <tr><td nowrap="nowrap">client a
        </td><td nowrap="nowrap">1
        </td><td class="currency PriceSold" nowrap="nowrap">
            &#36;25.75
        </td><td nowrap="nowrap">0
        </td><td class="currency" nowrap="nowrap">0
        </td><td nowrap="nowrap">0
        </td><td nowrap="nowrap">0
        </td><td class="currency" nowrap="nowrap">0
    </td></tr>
    <tr><td nowrap="nowrap">client b
        </td><td nowrap="nowrap">2
        </td><td class="currency PriceSold" nowrap="nowrap">
            &#36;31.44
        </td><td nowrap="nowrap">0
        </td><td class="currency" nowrap="nowrap">0
        </td><td nowrap="nowrap">0
        </td><td nowrap="nowrap">0
        </td><td class="currency" nowrap="nowrap">0
    </td></tr>
    <tr><td nowrap="nowrap">client a
        </td><td nowrap="nowrap">3
        </td><td class="currency PriceSold" nowrap="nowrap">
            &#36;15.92
        </td><td nowrap="nowrap">0
        </td><td class="currency" nowrap="nowrap">0
        </td><td nowrap="nowrap">0
        </td><td nowrap="nowrap">0
        </td><td class="currency" nowrap="nowrap">0
    </td></tr>
    <tr><td nowrap="nowrap">total:
        </td><td nowrap="nowrap">
        </td><td class="currency total1" nowrap="nowrap">
        </td><td nowrap="nowrap">
        </td><td class="currency" nowrap="nowrap">
        </td><td nowrap="nowrap">
        </td><td nowrap="nowrap">
        </td><td class="currency" nowrap="nowrap">
    </td></tr>
</table>

<script>
$(document).ready(function(){
  var total1 = 0.0;
  $('.PriceSold').each(function(){
    try{
      total1 += $(this).html().replace('$','') * 1;
    } catch(ex){}
  });
  $('.total1').html('<b>$' + total1+ '</b>');
});
</script>  

</body>
</html>
于 2012-11-18T20:22:20.600 に答える