您好我正在制作出席日期。在一个领域中有多个值用于出勤状态,如1表示缺席,3表示缺席,
例如:
public function attendanc_disc($site_id)
{
$y=date('Y-m');
$sql = "SELECT sch.*"
." FROM #__schedule AS sch"
." WHERE sch.start_date like '%".$y."%' and sch.site_id='".$site_id."' order by sch.start_date ASC"
;
$query = $this->db->query($sql);
return $query->result();
}
对于BAY这个日期2015-08-02应该显示一行,当前值应该是2,但我得到两行。
这是我的代码:
foreach ($sch_rows as $sch) {
if ($sch->reply_status_id == 1) {
$presentcnt +=1;
$class = 'success';
} else if ($sch->reply_status_id == 0) {
$not_res +=1;
$class = 'warning';
} else if ($sch->reply_status_id == 6) {
$CB_res +=1;
$class = 'alert-info';
} else {
$absent +=1;
$class = 'alert-danger';
}
$html .='<tr ><td class="' . $class . '"><a href="admin/schedule/assignment/true/' . $site->id . '" >' . $site->code . '</a></td><td><a href="index.php/admin/home/att_report/1/' . $site->id . '">' . $sch->start_date . '</a></td><td><a href="index.php/admin/home/att_report/1/' . $site->id . '">' . $presentcnt . '</a></td><td><a href="index.php/admin/home/att_report/1/' . $site->id . '">' . $absent . '</a></td><td><a href="index.php/admin/home/att_report/2/' . $site->id . '">' . $CB_res . '</a></td><td><a href="index.php/admin/home/att_report/3/' . $site->id . '">' . $not_res . '</a></td><td><a href="index.php/admin/home/att_report/4/' . $site->id . '">' . $CB_res . '</a></td></tr>';
我正在显示这个循环来调用这样的函数:
#Load packages
library(ggplot2)
library(sp)
#create spatial data
lon<-rnorm(10000,mean = 15,sd=1)
lat<-rnorm(10000,mean=45,sd=1)
data <-cbind.data.frame(lon,lat)
#create the heatmap
heatmap <- ggplot(data,aes(x=lon,y=lat))+ stat_density2d(data=data,
aes(x=lon, y=lat, fill=..level..,
alpha=..level..), geom="polygon")
# build the heatmap without plotting it
gb_heat <- ggplot_build(heatmap)
# extract the polygon specifications
gb_heat_dat <- gb_heat$data[[1]]
# make some polygons!
SpatialPolygons(lapply(unique(gb_heat_dat$group), function(x) {
pts <- gb_heat_dat[gb_heat_dat$group == x,]
Polygons(list(Polygon(as.matrix(data.frame(x=pts$x, y=pts$y)))), as.character(x))
})) -> polys
# plot them
plot(polys)
答案 0 :(得分:2)
你必须在你的SQL中使用案例
CASE
WHEN Responded== 3 THEN 1
ELSE 0
end
或者你必须在你的sql中使用if else并使用count关键字获取总礼物
$sql = "SELECT sch.start_date,COUNT(IF(reply_status_id = '1', 1,0)) AS `presentcnt`,COUNT(IF(reply_status_id = '0', 1,0)) AS `not_res FROM #__schedule AS sch WHERE sch.start_date like '%".$y."%' and sch.site_id='".$site_id."' order by sch.start_date ASC";