本文实例为大家分享了php实现按天数、星期、月份查询的搜索框,搜索时候展示数据的统计图,主要展示图形的效果,供大家参考,具体内容如下
1.ajax.php
$year = $_GET['y'];
if(!isset($_GET['m'])){
$month=1;
}else{
$month = $_GET['m'];
}
$week_arr = getMonthWeekArr($year, $month);
echo json_encode($week_arr);
die;
/**
* 获得系统某月的周数组,第一周不足的需要补足
*
* @param int $current_year
* @param int $current_month
* @return string[][]
*/
function getMonthWeekArr($current_year, $current_month){
//该月第一天
$firstday = strtotime($current_year.'-'.$current_month.'-01');
//该月的第一周有几天
$firstweekday = (7 - date('N',$firstday) +1);
//计算该月第一个周一的时间
$starttime = $firstday-3600*24*(7-$firstweekday);
//该月的最后一天
$lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day");
//该月的最后一周有几天
$lastweekday = date('N',$lastday);
//该月的最后一个周末的时间
$endtime = $lastday-3600*24*($lastweekday%7);
$step = 3600*24*7;//步长值
$week_arr = array();
for ($i=$starttime; $i
$week_arr[] = array('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6));
}
return $week_arr;
}
2.datehelper.php
//获得系统年份数组
/**
*
* @return string[]
*/
function getSystemYearArr(){
$year_arr = array('2010'=>'2010','2011'=>'2011','2012'=>'2012','2013'=>'2013','2014'=>'2014','2015'=>'2015','2016'=>'2016','2017'=>'2017','2018'=>'2018','2019'=>'2019','2020'=>'2020');
return $year_arr;
}
/**
* 获得系统月份数组
*
* @return array
*/
function getSystemMonthArr(){
$month_arr = array('1'=>'01','2'=>'02','3'=>'03','4'=>'04','5'=>'05','6'=>'06','7'=>'07','8'=>'08','9'=>'09','10'=>'10','11'=>'11','12'=>'12');
return $month_arr;
}
/**
* 获得系统周数组
*
* @return string[]
*/
function getSystemWeekArr(){
$week_arr = array('1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六','7'=>'周日');
return $week_arr;
}
/**
* 获取某月的最后一天
*
* @param int $year
* @param int $month
* @return number
*/
function getMonthLastDay($year, $month){
$t = mktime(0, 0, 0, $month + 1, 1, $year);
$t = $t - 60 * 60 * 24;
return $t;
}
/**
* 获得系统某月的周数组,第一周不足的需要补足
*
* @param int $current_year
* @param int $current_month
* @return string[][]
*/
function getMonthWeekArr($current_year, $current_month){
//该月第一天
$firstday = strtotime($current_year.'-'.$current_month.'-01');
//该月的第一周有几天
$firstweekday = (7 - date('N',$firstday) +1);
//计算该月第一个周一的时间
$starttime = $firstday-3600*24*(7-$firstweekday);
//该月的最后一天
$lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day");
//该月的最后一周有几天
$lastweekday = date('N',$lastday);
//该月的最后一个周末的时间
$endtime = $lastday-3600*24*($lastweekday%7);
$step = 3600*24*7;//步长值
$week_arr = array();
for ($i=$starttime; $i
$week_arr[] = array('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6));
}
return $week_arr;
}
/**
* 处理搜索时间
*/
function dealwithSearchTime($search_arr=''){
//初始化时间
//天
if(!isset($search_arr['search_time'])){
$search_arr['search_time'] = date('Y-m-d', time()- 86400);
}
$s