我有一个Android应用程序,用户将通过该应用程序登录和注销,但同时登录和注销的日期和时间应同时保存在数据库中。 我写的服务器脚本是
[code]
require_once('config.php'); //link to the database
$adminid = $_REQUEST['adminid']; //no default
$empid = $_REQUEST['empid']; //no default
$dailyentry = $_REQUEST['dailyentry']; //no default
$dailyexit = $_REQUEST['dailyexit']; //no default
$lunchin = $_REQUEST['lunchin']; //no default
$lunchout = $_REQUEST['lunchout']; //no default
$workin = $_REQUEST['workin']; //no default
$workout = $_REQUEST['workout']; //no default
$date=date("Y-m-d H:i:s");
if(mysql_query("INSERT INTO dailyattendance adminid empid dailyentry dailyexit lunchin lunchout workin workout VALUES('".$adminid."','".$empid."','".$dailyentry."','".$dailyexit."','".$lunchin."','".$lunchout."','".$workin."','".$workout."')");
$posts[0]['message'] = 'Successful';
$idd = mysql_insert_id();
$selectt = mysql_query("select * from dailyattendance where id = '".$idd."'");
$results = mysql_fetch_assoc($selectt);
$posts[0]['detail'] = $results;
header('Content-type: application/json');
echo json_encode($posts);
?>
[/code]
出现的问题是,我还希望用户在月末工作的总时数不过,但不知道如何操作。如果有人能帮助我编写工作时间的额外部分,我将不胜感激。
答案 0 :(得分:0)
你可以像下面这样做,
<?php
$totalHourofOffice = strtotime($dailyexit) - strtotime($dailyentry);
$totalHourofOffice = $totalHourofOffice/3600;
$totalLunchHour = strtotime($lunchin) - strtotime($lunchout);
$totalLunchHour = $totalLunchHour/3600;
$totalHour = totalHourofOffice - totalLunchHour;
?>