所以基本上我在我的模型中有一个TIMESTAMPDIFF查询来确定持续时间,我希望它在视图中显示持续时间。问题是,它会显示错误。
请帮帮我,谢谢。
这是我的模型查询(model_attendance.php):
public function getOne($username){
$sql = "SELECT empnum FROM employees WHERE username='$username'";
$result = $this->db->query($sql);
$sql1 = "SELECT a.empnum,CONCAT(a.name,' ',a.midname,' ',a.lastname) AS
NAME,CONCAT(b.indate,' ',b.intime) AS 'TIMEIN',CONCAT(b.outdate,'
',b.outtime)AS 'TIMEOUT', TIMESTAMPDIFF(HOUR, 'TIMEIN','TIMEOUT') AS 'DUR'
FROM employees AS a
JOIN times AS b ON (a.empnum=b.userid)
WHERE b.indate BETWEEN
DATE(CONCAT(YEAR(CURRENT_TIMESTAMP),'-',MONTH(CURRENT_TIMESTAMP),'-','01'))
AND DATE(LAST_DAY(CURRENT_TIMESTAMP)) AND b.userid='".$result->row(0)->empnum."'";
$query = $this->db->query($sql1);
return $query->result();
}
答案 0 :(得分:1)
要解决此问题,您需要将返回类型传递为" false"到活动记录选择查询。
$this->db->select("TIMESTAMPDIFF(YEAR,a.date_birth, CURDATE()) AS age", false);
答案 1 :(得分:0)
将其分配给变量并将其传递给SQL Query。
.centerSectionDivs{
margin:0 auto;
}
答案 2 :(得分:0)
它可能是一个错误。我还没有检查过Query Builder类。但要解决这个问题......您可以尝试将`添加到像这样的列
$this->db->select("TIMESTAMPDIFF(YEAR, `a.date_birth`, CURDATE()) AS age");
或
$this->db->query("TIMESTAMPDIFF(YEAR, `a.date_birth`, CURDATE()) AS age");