|
 |
|
ต้องการ query หาผลรวมของเวลาใน mysql ที่ฟิลด์ของเวลาเป็น char(10) |
|
 |
|
|
 |
 |
|
ขอโค้ด คำนวนเวลาหน่อยนะค่ะ คือว่าตอนนี้เขียนโปรแกรมคำนวณ OT
นำข้อมูลลงฐานข้อมูลแล้วจะนำ OT มาหาผลรวมทั้งหมด
ตัวอย่าง
02:00
02:00
ผลรวม 4 ชั่วโมง
ฟังก์ชัน
Code (PHP)
<?php
function timeplus($arr)
{
$minute = 0;
$second = 0;
foreach ($arr as $value)
{
$arrtime = explode(":", $value);
$minute += $arrtime[0];
$second += $arrtime[1];
}
return ($minute + floor($second / 60)) . ":" . str_pad(($second % 60), 2, "0" , STR_PAD_LEFT);
}
?>
การเรียกใช้
Code (PHP)
<?php
$arr = array("11:30", "15:53", "5:42");
echo "รวมเวลา : " . timeplus($arr);
?>
ใช้โค้ดนี้แต่ไม่ได้เพราะต้องดึงจากฐานข้อมูลออกมา โดยใช้ while($row = mysql_fetch_array($result, MYSQL_BOTH))
แล้วมันไม่ยอมคำนวณ
*****ช่วยหน่อยนะค่ะ
|
 |
 |
 |
 |
Date :
2012-06-26 22:35:08 |
By :
jubjang |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|