[英]PHP echoed variable returns a mysql query string
Im currently new to php, i figured this is the right place to ask.我目前是 php 的新用户,我认为这是正确的提问地点。 When i tried to echo $empshift variable.当我试图回应 $empshift 变量时。 it says in the browsers console它在浏览器控制台中说
("SELECT SHIFT_START FROM myilogin_46.DATE_TIME_RECORDS WHERE ID = '' and r_status = 'A'"). (“SELECT SHIFT_START FROM myilogin_46.DATE_TIME_RECORDS WHERE ID = '' and r_status = 'A'”)。
As You can see it returns the string or the query itself, not the actual value of the query.如您所见,它返回字符串或查询本身,而不是查询的实际值。
How do I do it so that $empshift
would really return the value of the query (for example: in the database SHIFT_START
column is a time datatype-> 08:30:00
in this format.).我该怎么做才能使$empshift
真正返回查询的值(例如:数据库中的SHIFT_START
列是时间数据类型 -> 08:30:00
这种格式。)。
I figured this was the reason why I can't subtract $empshift
to $alterin
.我认为这就是我不能将$alterin
减去$empshift
的原因。
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();
this is the select () function in the Database class:这是数据库class中的select()function:
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();
}
}
I got it, I didnt assign the query to as a variable.我明白了,我没有将查询分配给变量。 instead i used for each and a getResult function.相反,我使用了每个和一个 getResult function。
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; //
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.