PHP响应变量返回一个mysql查询字符串



我目前是php的新手,我认为这是一个合适的问题。当我试图回显$empshift变量时。它说在浏览器控制台

(从myilogin_46.DATE_TIME_RECORDS中选择偏移_START,ID="r_status="A"(。

如您所见,它返回字符串或查询本身,而不是查询的实际值。

我该如何做才能使$empshift真正返回查询的值(例如:在数据库中,SHIFT_START列是一个时间数据类型-这种格式的08:30:00。(

我想这就是为什么我不能把$empshift减去$alterin的原因。

foreach ($rs as $key => $value) {
$db = new Database();
$db->connect();
date_default_timezone_set('Asia/Ho_Chi_Minh');
$empshift = $db->select(array('myilogin_46.DATE_TIME_RECORDS'),'SHIFT_START',"ID = '".$id."' and r_status = 'A'");
echo $empshift; //SELECT SHIFT_START FROM myilogin_46.DATE_TIME_RECORDS WHERE ID = '' and r_status = 'A'<br />
$sched = $empshift;
$alterin = date('H:i:s',strtotime($value['alterIN']));//
echo $alterin;//08:33
echo $sched;
$late = $alterin-$sched;
$db->update_imp('myilogin_46.DATE_TIME_RECORDS',array(
'date_in'=>date('Y-m-d',strtotime($value['alterIN']))
,'time_in_info'=>'ALTERED IN'
,'time_out_info'=>'ALTERED OUT' 
,'time_in'=>date('H:i',strtotime($value['alterIN']))
,'time_out'=>date('H:i',strtotime($value['alterOUT']))
,'date_out'=>date('Y-m-d',strtotime($value['alterOUT']))
,'late'=>$late
),"id = '".$value['dtrID']."' and id_emp = '".$value['empID']."' and R_STATUS = 'A'");
// echo date('H:i:s',strtotime($late));
$db->disconnect();

这是Database类中的select((函数:

public function select($table = array(), $column = '*', $where = null, $order = null, $limit = null){

$qry = 'SELECT '.$column.' FROM '.implode(', ',$table);
if($where != null){
$qry .= ' WHERE '.$where;
}
if($order != null){
$qry .= ' ORDER BY '.$order;
}
if($limit != null){
$qry .= ' LIMIT '.$limit;
}
//   echo $qry.'</br></br>';
//   exit();
if ($this->sql($qry)) {
return $qry;
} else {
echo 'dbselect sql error: '.$qry;
exit();
}

}

我得到了它,我没有将查询分配为变量。相反,我使用了for each和一个getResult函数。

foreach ($rs as $key => $value) {
$db=new Database();
$db->connect();

$alterin= date('H:i:s', strtotime($value['alterIN']));
$db->select(array('myilogin_46.DATE_TIME_RECORDS'),'SHIFT_START'
,"ID = '".$value['dtrID']."' and R_STATUS='A'");
foreach ($db->getResult() as $key => $value) {
$shiftstart = $value['SHIFT_START'];
}

$late= $alterin -  $shiftstart;
// if($shiftstart >= $alterin){
//    $late= "00:00:00";

// }elseif ($shiftstart > $alterin) {
//     # code...
//     $late= $alterin - $shiftstart;

// }

echo $shiftstart;
echo $alterin;
echo $late; //

最新更新