//查询部门 $sql_depart="SELECT * FROM depart WHERE gid>0 AND gid<15 ORDER BY gid"; $query_depart=$db->query($sql_depart); while($d=$db->fetch_array($query_depart)){ ?>
//查询人员
$sql_user="SELECT * FROM members WHERE flag<5 and groupid='".$d['gid']."' ORDER BY flag desc"; $query_user=$db->query($sql_user); while($u=$db->fetch_array($query_user)){ ?>
//查询所有日志 $sql="SELECT c1.*,c2.* FROM log c1 LEFT JOIN log_time c2 ON (c1.time_id=c2.tid) WHERE c2.year='".$year."' AND c1.userid='".$u['uid']."' AND c2.end_date<'".date("Y-m-d")."' ORDER BY c2.tid desc"; $query=$db->query($sql); while($row=$db->fetch_array($query)){
SELECT d.*,m.*,l.* FROM depart d left join members m on m.flag<5 and m.groupid = d.gid left join (SELECT c1.*,c2.* FROM log c1 LEFT JOIN log_time c2 ON (c1.time_id=c2.tid) WHERE c2.year='".$year."' AND c2.end_date<'".date("Y-m-d")."') l on l.userid = m.uid WHERE d.gid>0 AND d.gid<15 ORDER BY d.gid,m.flag desc,l.tid desc