html table sum,php - Multiple HTML tables sum column of each table - Stack Overflow

I have a HTML table which is generated by PHP,

Each table has a dynamic ID assigned to it

What i would like is a total of the time in the "Worked Time" column for each table.

MArlj.png

Visitor Sign In Admin

Cleaner Report (Today)

Todays report for cleaners

date_default_timezone_set('Europe/London');

include $con=mysqli_connect($hostname,$username,$password,"visitorsignin");

$sql = "SELECT staff_badgeid,first_name,last_name,signintime,signouttime FROM `signin_entries` WHERE iscleaner ='YES' AND signindate = curdate() ORDER BY staff_badgeid ASC";

$list_visitors_result=mysqli_query($con, $sql);

$count_visitors = mysqli_num_rows($list_visitors_result);

if ($count_visitors != 0) {

$current_badgeid = '';

while ($row = mysqli_fetch_array($list_visitors_result)) {

if ($current_badgeid == '') {

$current_badgeid = $row['staff_badgeid']; //define if empty, for the first table

echo "

}

if($row['staff_badgeid'] != $current_badgeid){

echo "


Total:

$current_badgeid = $row['staff_badgeid'];

}

$signintime = $row['signintime'];

$signouttime = $row['signouttime'];

$firstname = $row['first_name'];

$lastname = $row['last_name'];

echo "

$firstname $lastname$signintime";

if ($signouttime == "") {

echo "

Not Signed Out Yet";

} else {

echo "

$signouttime";

}

$timeFirst = strtotime(date("Y/m/d") . " " . $signintime);

$timeSecond = strtotime(date("Y/m/d") ." " . $signouttime);

//below checks if th second time is less than the first time than it must be from the day before so add 24 hours eg (signin time 23:30:00 signout time 07:30:30 would be 08:00:30 difference)

if ($timeSecond < $timeFirst) {

$timeSecond = $timeSecond + 86400;

}

if ($signouttime == "") {

echo "

Cleaner Has Not Signed Out Yet";

} else {

$differenceInSeconds = $timeSecond - $timeFirst;

echo "

".converttime($differenceInSeconds)."";

}

echo "

";

}

echo "

Total:";

}

//below function converts the seconds difference into hh:mm:ss format to the nearest second

function converttime($seconds) {

$t = round($seconds);

return sprintf('%02d:%02d:%02d', ($t/3600),($t/60%60), $t%60);

}

?>

What would be the best solution? I'm currently stuck on the logic of referring to each table i did have this code which only applied to the first table due to the code referring to a single ID so only the first table worked correctly....is there anyway i could amend this to apply to the dynamic ID's now being applied?

//below script taken from http://jsfiddle.net/unKDk/192/ looks at table id then column id called id rowDataSd

//

$(window).load(function(){

var totals = [[0,0,0], [0,0,0], [0,0,0]];

$(document).ready(function () {

var $dataRows = $("#sum_table tr:not('.totalColumn, .titlerow')");

$dataRows.each(function () {

$(this).find('.rowDataSd').each(function (i) {

time = $(this).html().split(":")

totals[i][2] += parseInt(time[2]);

if(totals[i][2] > 60)

{

totals[i][2] %= 60;

totals[i][1] += parseInt(time[1]) + 1;

}

else

totals[i][1] += parseInt(time[1]);

if(totals[i][1] > 60)

{

totals[i][1] %= 60;

totals[i][0] += parseInt(time[0]) + 1;

}

else

totals[i][0] += parseInt(time[0]);

});

});

$("#sum_table td.totalCol").each(function (i) {

console.log(totals[i]);

$(this).html("" + totals[i][0] + ":" + totals[i][1] + ":" + totals[i][2]);

});

});

});

//]]>

If i change the script to refer to the table class as suggested i get a total of all tables "Worked Time" in the first table, I want a total of "Worked Time" per table

PHlks.png

This is incorrect as the first table show a total of both tables "Worked Time" columns, each table should have separate totals from their own tables.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值