foreach循环查询
//客户端考勤
public function doPageKaoqin()
{
global $_GPC, $_W;
$errno = 0;
$message = 'success';
$starttime = $_GPC['starttime'];//开始时间
$endtime = $_GPC['endtime'];//结束时间
$list = pdo_fetchall("SELECT a.id,a.course_id, a.section_id, b.name course_name FROM " . tablename('wx_school_my_hours') . " a LEFT JOIN "
. tablename('wx_school_tcourse') . " b ON a.course_id=b.id WHERE a.date >= '$starttime' and a.date<= '$endtime' ORDER BY a.date DESC");
$total= 0;
$total_que = 0;
foreach ($list as &$value) {
$value['total_stu'] = pdo_fetchcolumn("SELECT COUNT(1) FROM " . tablename('wx_school_sign_log') . " WHERE hours_id = {$value['id']}");
$total += $value['total_stu'];
$value['que_stu'] = pdo_fetchcolumn("SELECT COUNT(1) FROM " . tablename('wx_school_sign_log') . " WHERE hours_id = {$value['id']} AND status=2");
$total_que += $value['que_stu'];
}
return $this->result($errno, $message, [
'config'=>['total'=>$total, 'total_que'=>$total_que],
'list'=>$list
]);
}
foreach 循环查询2
public function doPageWorkCompletion()
{
global $_GPC, $_W;
$errno = 0;
$message = 'success';
$data = pdo_fetchall("SELECT id,name,work_starttime,work_endtime FROM".tablename('wx_school_kcbiao')."WHERE work IS NOT NULL");
foreach ($data as $k=>&$v){
$data[$k]['work_starttime'] = date("m月d日 H:i",$data[$k]['work_starttime']);
$data[$k]['work_endtime'] = date("m月d日 H:i",$data[$k]['work_endtime']);
$data[$k]['wancheng'] = pdo_fetchcolumn("SELECT count(*) FROM". tablename('wx_school_homework')."WHERE section_id = {$v['id']} and status = 1");
$data[$k]['total'] = pdo_fetchcolumn("SELECT count(*) FROM". tablename('wx_school_homework')."WHERE section_id = {$v['id']}");
}
return $this->result($errno, $message, $data);
}