Javascript 对表中的列值求和

Javascript 对表中的列值求和,javascript,php,jquery,Javascript,Php,Jquery,我试图将“分配的总工时”和“未调用”列的值相加 这是我的表格HTML <table border=1 id="category"> <tr> <th>User Name</th> <th>User Belongs</th> <th>Total Work Assigned</th> <th>Not Called</

我试图将“分配的总工时”和“未调用”列的值相加

这是我的
表格
HTML

<table border=1 id="category">
    <tr>
        <th>User Name</th>
        <th>User Belongs</th>
        <th>Total Work Assigned</th>
        <th>Not Called</th>
    </tr>
    <tr>
        <td>vidyaranyapura</td>
        <td>Category</td>
        <td>172</td>
        <td>156</td>
    </tr>
    <tr>
        <td>sahasra</td>
        <td>Company</td>
        <td>500</td>
        <td>350</td>
    </tr>
    <tr>
        <td>global</td>
        <td>Not Assigned</td>
        <td>0</td>
        <td>0</td>
    </tr>
</table>

用户名
用户属于
分配的总工作量
不打电话
维迪亚兰亚普拉酒店
类别
172
156
萨哈斯拉
单位
500
350
全球的
未分配
0
0
我的预期产出
用户名
用户属于
分配的总工作量
不打电话
维迪亚兰亚普拉酒店
类别
172
156
萨哈斯拉
单位
500
350
全球的
未分配
0
0
672
506

我想你想做的事情是这样的:

演示:

isNumeric()函数引自以下答案:

HTML:


用户名
用户属于
分配的总工作量
不打电话
维迪亚兰亚普拉酒店
类别
172
156
萨哈斯拉
单位
500
350
全球的
未分配
0
0

希望这能有所帮助。

我想你想做的是:

演示:

isNumeric()函数引自以下答案:

HTML:


用户名
用户属于
分配的总工作量
不打电话
维迪亚兰亚普拉酒店
类别
172
156
萨哈斯拉
单位
500
350
全球的
未分配
0
0

希望这有帮助。

基于您在小提琴中提供的
PHP
。实际上,您可以在循环遍历这些值以将其输出到显示器时对这些值进行合计

只需更换此
foreach
部分

$table2 = '<table  id="all_category_data" class="table table-striped table-bordered table-hover"><tr><th>User Name</th><th>User Belongs to</th><th>Total Work Assigned</th><th>Not Called</th><th>Follow Up</th><th>Intrested</th><th>Not Intrested</th></tr>';

foreach($totalresult as $totalresults) {
    $table2 .= "<tr><td>".$totalresults['username'].
    "</td><td>".$totalresults['userbelongs'].
    "</td><td>".$totalresults['totalvalue'].
    "</td><td>".$totalresults['Notcalled'].
    "</td><td>".$totalresults['followUp'].
    "</td><td>".$totalresults['intrested'].
    "</td><td>".$totalresults['notIntrested'].
    "</td></tr>";
}

$table2. = '</table>';

echo $table2;
$table2='User NameUser属于分配的全部工作,不调用UpIntrestedNot Intrested';
foreach($totalresult作为$totalresults){
$table2.=''.$totalresults['username']。
“”.$totalresults['UserOwners']。
“”.$totalresults['totalvalue']。
“”.$totalresults['Notcalled']。
“”.$totalresults['followUp']。
“”.$totalresults['Intrest']。
“”.$totalresults['NotIntrest']。
"";
}
$table2.='';
表2;
包括添加和输出的以下内容

$table2 = '<table  id="all_category_data" class="table table-striped table-bordered table-hover"><tr><th>User Name</th><th>User Belongs to</th><th>Total Work Assigned</th><th>Not Called</th><th>Follow Up</th><th>Intrested</th><th>Not Intrested</th></tr>';
$totalValue = 0;
$notCalledValue = 0;
foreach($totalresult as $totalresults) {
    // addition of totalValue
    $totalValue = $totalValue + $totalresults['totalvalue'];
    // addition of notCalledValue
    $notCalledValue = $notCalledValue + $totalresults['Notcalled'];

    $table2 .= "<tr><td>".$totalresults['username'].
    "</td><td>".$totalresults['userbelongs'].
    "</td><td>".$totalresults['totalvalue'].
    "</td><td>".$totalresults['Notcalled'].
    "</td><td>".$totalresults['followUp'].
    "</td><td>".$totalresults['intrested'].
    "</td><td>".$totalresults['notIntrested'].
    "</td></tr>";
}
// output of totalValue and notCalledValue
$table2 .= "<tr><td>".
    "</td><td>".
    "</td><td>".$totalValue.
    "</td><td>".$notCalledValue.
    "</td><td>".
    "</td><td>".
    "</td><td>".
    "</td></tr>";

$table2. = '</table>';
echo $table2;
$table2='User NameUser属于分配的全部工作,不调用UpIntrestedNot Intrested';
$totalValue=0;
$notCalledValue=0;
foreach($totalresult作为$totalresults){
//总值相加
$totalValue=$totalValue+$totalresults['totalValue'];
//添加notCalledValue
$notCalledValue=$notCalledValue+$totalresults['Notcalled'];
$table2.=''.$totalresults['username']。
“”.$totalresults['UserOwners']。
“”.$totalresults['totalvalue']。
“”.$totalresults['Notcalled']。
“”.$totalresults['followUp']。
“”.$totalresults['Intrest']。
“”.$totalresults['NotIntrest']。
"";
}
//totalValue和notCalledValue的输出
$table2.=''。
"".
“”.$totalValue。
“”.$notCalledValue。
"".
"".
"".
"";
$table2.='';
表2;

注意:这假设数据中的
$totalresults['totalvalue']
$totalresults['Notcalled']
键是数字。

基于您在小提琴中提供的
PHP
。实际上,您可以在循环遍历这些值以将其输出到显示器时对这些值进行合计

只需更换此
foreach
部分

$table2 = '<table  id="all_category_data" class="table table-striped table-bordered table-hover"><tr><th>User Name</th><th>User Belongs to</th><th>Total Work Assigned</th><th>Not Called</th><th>Follow Up</th><th>Intrested</th><th>Not Intrested</th></tr>';

foreach($totalresult as $totalresults) {
    $table2 .= "<tr><td>".$totalresults['username'].
    "</td><td>".$totalresults['userbelongs'].
    "</td><td>".$totalresults['totalvalue'].
    "</td><td>".$totalresults['Notcalled'].
    "</td><td>".$totalresults['followUp'].
    "</td><td>".$totalresults['intrested'].
    "</td><td>".$totalresults['notIntrested'].
    "</td></tr>";
}

$table2. = '</table>';

echo $table2;
$table2='User NameUser属于分配的全部工作,不调用UpIntrestedNot Intrested';
foreach($totalresult作为$totalresults){
$table2.=''.$totalresults['username']。
“”.$totalresults['UserOwners']。
“”.$totalresults['totalvalue']。
“”.$totalresults['Notcalled']。
“”.$totalresults['followUp']。
“”.$totalresults['Intrest']。
“”.$totalresults['NotIntrest']。
"";
}
$table2.='';
表2;
包括添加和输出的以下内容

$table2 = '<table  id="all_category_data" class="table table-striped table-bordered table-hover"><tr><th>User Name</th><th>User Belongs to</th><th>Total Work Assigned</th><th>Not Called</th><th>Follow Up</th><th>Intrested</th><th>Not Intrested</th></tr>';
$totalValue = 0;
$notCalledValue = 0;
foreach($totalresult as $totalresults) {
    // addition of totalValue
    $totalValue = $totalValue + $totalresults['totalvalue'];
    // addition of notCalledValue
    $notCalledValue = $notCalledValue + $totalresults['Notcalled'];

    $table2 .= "<tr><td>".$totalresults['username'].
    "</td><td>".$totalresults['userbelongs'].
    "</td><td>".$totalresults['totalvalue'].
    "</td><td>".$totalresults['Notcalled'].
    "</td><td>".$totalresults['followUp'].
    "</td><td>".$totalresults['intrested'].
    "</td><td>".$totalresults['notIntrested'].
    "</td></tr>";
}
// output of totalValue and notCalledValue
$table2 .= "<tr><td>".
    "</td><td>".
    "</td><td>".$totalValue.
    "</td><td>".$notCalledValue.
    "</td><td>".
    "</td><td>".
    "</td><td>".
    "</td></tr>";

$table2. = '</table>';
echo $table2;
$table2='User NameUser属于分配的全部工作,不调用UpIntrestedNot Intrested';
$totalValue=0;
$notCalledValue=0;
foreach($totalresult作为$totalresults){
//总值相加
$totalValue=$totalValue+$totalresults['totalValue'];
//添加notCalledValue
$notCalledValue=$notCalledValue+$totalresults['Notcalled'];
$table2.=''.$totalresults['username']。
“”.$totalresults['UserOwners']。
“”.$totalresults['totalvalue']。
“”.$totalresults['Notcalled']。
“”.$totalresults['followUp']。
“”.$totalresults['Intrest']。
“”.$totalresults['NotIntrest']。
"";
}
//totalValue和notCalledValue的输出
$table2.=''。
"".
“”.$totalValue。
“”.$notCalledValue。
"".
"".
"".
"";
$table2.='';
表2;

注意:这假设数据中的
$totalresults['totalvalue']
$totalresults['Notcalled']
键是数字。

您的意思是说不想要tp前两条记录,对吗?如果您试图合计第三列和第四列,为什么要在模板呈现后这样做?为什么不在生成时将其合计?你们在使用什么样的模板库,你们是如何输出你们的表的?是的,我不想要第一个2records@haxxxton,我正在使用
php
并且
数据是从
mysql数据库中获取的
你能发布你用来输出表的
php
代码吗?你的意思是说不想要前两条记录,对吗?如果你试图合计第三列和第四列,为什么要在模板呈现后这样做?为什么不在生成时将其合计?你们在使用什么样的模板库,你们是如何输出你们的表的?是的,我不想要第一个