Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何对计算表列求和_Php_Javascript_Mysql_Joomla - Fatal编程技术网

Php 如何对计算表列求和

Php 如何对计算表列求和,php,javascript,mysql,joomla,Php,Javascript,Mysql,Joomla,我需要对显示的表中的一列求和。 我的问题是: 如何对已从其他列计算数据的表列求和? 我需要使用javascript来完成吗? 我想在相关列的底部显示总数。 提前感谢您的建议 我当前计算数据的示例: echo round(($r->price_sold - $r->shipping - $r->tax - $r->fees) * $r->commission_rate / 100,2); $query = " SELECT * FROM jos_da

我需要对显示的表中的一列求和。 我的问题是: 如何对已从其他列计算数据的表列求和? 我需要使用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>';

在我写一个巨大的答案之前,你在使用库吗?Joomla附带jquery,我想?@Asad-Joomla 3.0附带jquery。Joomla1.5和2.5随mootools一起提供,但导入jQuery并没有错;我很想用这种方法,但我不能让它工作。你能进一步解释一下吗,或者把它插入原代码中应该放在哪里?我可能用错地方了。感谢我制作的工作样本:刚刚更换&36;有了$Thank Boris,它自己就可以工作了,但我无法让它与计算如下的列一起工作:echo;回声&36;;回音轮$r->售价-$r->费用-$r->税收-$r->运费-$r->售价-$r->费用-$r->税收-$r->运费-$r->佣金率/100,2;对于每一列,您可以输入unicue classname并选择像第一列这样的值,然后进行计算。看看,td单元里面是什么。使用Chrome,右键单击单元格->分析元素。向我发送生成的html
<!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>