Table of Contents
php implements a search box for querying by days, weeks, and months, php days
Home Backend Development PHP Tutorial PHP implements a search box for querying by days, weeks, and months, PHP days_PHP tutorial

PHP implements a search box for querying by days, weeks, and months, PHP days_PHP tutorial

Jul 12, 2016 am 08:53 AM
mysql php days search bar Week month

php implements a search box for querying by days, weeks, and months, php days

The example in this article shares with you a php search box that implements querying by days, weeks, and months, search The statistical chart of the data is displayed at this time, mainly showing the effect of the graph for your reference. The specific content is as follows

1.ajax.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

<&#63;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<$endtime; $i= $i+3600*24*7){

    $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;

}

Copy after login

2.datehelper.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

<&#63;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<$endtime; $i= $i+3600*24*7){

    $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);

    }

  

    $search_arr['day']['search_time'] = strtotime($search_arr['search_time']);//搜索的时间

    //周

    if(!isset($search_arr['searchweek_year'])){

      $search_arr['searchweek_year'] = date('Y', time());

    }

    if(!isset($search_arr['searchweek_month'])){

      $search_arr['searchweek_month'] = date('m', time());

    }

    if(!isset($search_arr['searchweek_week'])){

      $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(time()));

    }

  

  

    $weekcurrent_year = $search_arr['searchweek_year'];

    $weekcurrent_month = $search_arr['searchweek_month'];

    $weekcurrent_week = $search_arr['searchweek_week'];

    $search_arr['week']['current_year'] = $weekcurrent_year;

    $search_arr['week']['current_month'] = $weekcurrent_month;

    $search_arr['week']['current_week'] = $weekcurrent_week;

  

    //月

    if(!isset($search_arr['searchmonth_year'])){

      $search_arr['searchmonth_year'] = date('Y', time());

    }

    if(!isset($search_arr['searchmonth_month'])){

      $search_arr['searchmonth_month'] = date('m', time());

    }

    $monthcurrent_year = $search_arr['searchmonth_year'];

    $monthcurrent_month = $search_arr['searchmonth_month'];

    $search_arr['month']['current_year'] = $monthcurrent_year;

    $search_arr['month']['current_month'] = $monthcurrent_month;

    return $search_arr;

  }

  

  /**

   * 获取本周的开始时间和结束时间

   *

   * @param int $current_time

   * @return string

   */

  function getWeek_SdateAndEdate($current_time){

      

    $current_time = strtotime(date('Y-m-d',$current_time));

    $return_arr['sdate'] = date('Y-m-d', $current_time-86400*(date('N',$current_time) - 1));

    $return_arr['edate'] = date('Y-m-d', $current_time+86400*(7- date('N',$current_time)));

      

    return $return_arr;

  }

  /**

   * 查询每月的周数组

   */

 function getweekofmonth(){

    $year = $_GET['y'];

    $month = $_GET['m'];

    $week_arr = getMonthWeekArr($year, $month);

    echo json_encode($week_arr);

    die;

  }

Copy after login

3.statistics.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

<&#63;php

/**

 * 统计

 *

 * @abstract

 *

 * @copyright 格里西,2016

 *

 * @author liujun

 *

 * @version Id:statics v1.0 2016/2/5

 */

  

/**

 * 获得折线图统计图数据

 *

 * param $statarr 图表需要的设置项

 * @return string

 */

function getStatData_LineLabels($stat_arr){

    

  //图表区、图形区和通用图表配置选项

  $stat_arr['chart']['type'] = 'line';

  //图表序列颜色数组

  $stat_arr['colors']&#63;'':$stat_arr['colors'] = array('#058DC7', '#ED561B', '#8bbc21', '#0d233a');

  //去除版权信息

  $stat_arr['credits']['enabled'] = false;

  //导出功能选项

  $stat_arr['exporting']['enabled'] = false;

  //标题如果为字符串则使用默认样式

  is_string($stat_arr['title'])&#63;$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):'';

  //子标题如果为字符串则使用默认样式

  is_string($stat_arr['subtitle'])&#63;$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):'';

  //Y轴如果为字符串则使用默认样式

  if(is_string($stat_arr['yAxis'])){

    $text = $stat_arr['yAxis'];

    unset($stat_arr['yAxis']);

    $stat_arr['yAxis']['title']['text'] = $text;

  }

  return json_encode($stat_arr);

}

  

/**

 * 获得Column2D统计图数据

 *

 * @param array $stat_arr

 * @return string

 */

function getStatData_Column2D($stat_arr){

    

  //图表区、图形区和通用图表配置选项

  $stat_arr['chart']['type'] = 'column';

  //去除版权信息

  $stat_arr['credits']['enabled'] = false;

  //导出功能选项

  $stat_arr['exporting']['enabled'] = false;

  //标题如果为字符串则使用默认样式

  is_string($stat_arr['title'])&#63;$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):'';

  //子标题如果为字符串则使用默认样式

  is_string($stat_arr['subtitle'])&#63;$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):'';

  //Y轴如果为字符串则使用默认样式

  if(is_string($stat_arr['yAxis'])){

    $text = $stat_arr['yAxis'];

    unset($stat_arr['yAxis']);

    $stat_arr['yAxis']['title']['text'] = $text;

  }

  //柱形的颜色数组

  $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7');

    

  foreach ($stat_arr['series'] as $series_k=>$series_v){

    foreach ($series_v['data'] as $data_k=>$data_v){

      $data_v['color'] = $color[$data_k];

      $series_v['data'][$data_k] = $data_v;

    }

    $stat_arr['series'][$series_k]['data'] = $series_v['data'];

  }

  //print_r($stat_arr); die;

  return json_encode($stat_arr);

}

  

/**

 * 获得Basicbar统计图数据

 *

 * @param array $stat_arr

 * @return string

 */

function getStatData_Basicbar($stat_arr){

    

  //图表区、图形区和通用图表配置选项

  $stat_arr['chart']['type'] = 'bar';

  //去除版权信息

  $stat_arr['credits']['enabled'] = false;

  //导出功能选项

  $stat_arr['exporting']['enabled'] = false;

  //显示datalabel

  $stat_arr['plotOptions']['bar']['dataLabels']['enabled'] = true;

  //标题如果为字符串则使用默认样式

  is_string($stat_arr['title'])&#63;$stat_arr['title'] = array('text'=>"<b>{$stat_arr['title']}</b>",'x'=>-20):'';

  //子标题如果为字符串则使用默认样式

  is_string($stat_arr['subtitle'])&#63;$stat_arr['subtitle'] = array('text'=>"<b>{$stat_arr['subtitle']}</b>",'x'=>-20):'';

  //Y轴如果为字符串则使用默认样式

  if(is_string($stat_arr['yAxis'])){

    $text = $stat_arr['yAxis'];

    unset($stat_arr['yAxis']);

    $stat_arr['yAxis']['title']['text'] = $text;

  }

  //柱形的颜色数组

  $color = array('#7a96a4','#cba952','#667b16','#a26642','#349898','#c04f51','#5c315e','#445a2b','#adae50','#14638a','#b56367','#a399bb','#070dfa','#47ff07','#f809b7');

    

  foreach ($stat_arr['series'] as $series_k=>$series_v){

    foreach ($series_v['data'] as $data_k=>$data_v){

      if (!$data_v['color']){

        $data_v['color'] = $color[$data_k%15];

      }

      $series_v['data'][$data_k] = $data_v;

    }

    $stat_arr['series'][$series_k]['data'] = $series_v['data'];

  }

  //print_r($stat_arr); die;

  return json_encode($stat_arr);

}

  

/**

 * 计算环比

 *

 * @param array $updata

 * @param array $currentdata

 * @return string

 */

function getHb($updata, $currentdata){

    

  if($updata != 0){

    $mtomrate = round(($currentdata - $updata)/$updata*100, 2).'%';

  } else {

    $mtomrate = '-';

  }

  return $mtomrate;

}

  

/**

 * 计算同比

 *

 * @param array $updata

 * @param array $currentdata

 * @return string

 */

function getTb($updata, $currentdata){

    

  if($updata != 0){

    $ytoyrate = round(($currentdata - $updata)/$updata*100, 2).'%';

  } else {

    $ytoyrate = '-';

  }

  return $ytoyrate;

}

  

/**

 * 地图统计图

 *

 * @param array $stat_arr

 * @return string

 */

function getStatData_Map($stat_arr){

    

  //$color_arr = array('#f63a3a','#ff5858','#ff9191','#ffc3c3','#ffd5d5');

  $color_arr = array('#fd0b07','#ff9191','#f7ba17','#fef406','#25aae2');

  $stat_arrnew = array();

  foreach ($stat_arr as $k=>$v){

    $stat_arrnew[] = array('cha'=>$v['cha'],'name'=>$v['name'],'des'=>$v['des'],'color'=>$color_arr[$v['level']]);

  }

  return json_encode($stat_arrnew);

}

  

/**

 * 获得饼形图数据

 *

 * @param array $data

 * @return string

 */

function getStatData_Pie($data){

    

  $stat_arr['chart']['type'] = 'pie';

  $stat_arr['credits']['enabled'] = false;

  $stat_arr['title']['text'] = $data['title'];

  $stat_arr['tooltip']['pointFormat'] = '{series.name}: <b>{point.y}</b>';

  $stat_arr['plotOptions']['pie'] = array(

    'allowPointSelect'=>true,

    'cursor'=>'pointer',

    'dataLabels'=>array(

      'enabled'=>$data['label_show'],

      'color'=>'#000000',

      'connectorColor'=>'#000000',

      'format'=>'<b>{point.name}</b>: {point.percentage:.1f} %'

    )

  );

  $stat_arr['series'][0]['name'] = $data['name'];

  $stat_arr['series'][0]['data'] = array();

  foreach ($data['series'] as $k=>$v){

    $stat_arr['series'][0]['data'][] = array($v['p_name'],$v['allnum']);

  }

  //exit(json_encode($stat_arr));

  return json_encode($stat_arr);

}

Copy after login

4.theline.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

<!DOCTYPE>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!--引入ECharts文件-->

<title>Echarts</title>

<script src="js/echarts.common.min.js"></script>

</head>

<script src="js/jquery.js"></script>

<&#63;php include('php/datehelper.php');include('php/statistics.php');&#63;>

<&#63;php

  

      //获得系统年份

      $year_arr = getSystemYearArr();

      //获得系统月份

      $month_arr = getSystemMonthArr();

      //存储参数

      $search_arr = $_REQUEST;

      $search_arr =dealwithSearchTime($search_arr);

      //获得本月的周时间段

      $week_arr = getMonthWeekArr($search_arr['week']['current_year'],$search_arr['week']['current_month']);

      //天数

      if(!isset($_REQUEST['search_time'])){

        $_REQUEST['search_time'] = date('Y-m-d', time()-86400);

      }

      $search_time = $_REQUEST['search_time'];//搜索的时间

        //周

      if(!isset($_REQUEST['search_time_year'])){

        $_REQUEST['search_time_year'] = date('Y', time());

      }

      if(!isset($_REQUEST['search_time_month'])){

        $_REQUEST['search_time_month'] = date('m', time());

      }

      if(!isset($_REQUEST['search_time_week'])){

        $_REQUEST['search_time_week'] = implode('|', getWeek_SdateAndEdate(time()));

      }

        

      $current_year = $_REQUEST['search_time_year'];

      $current_month = $_REQUEST['search_time_month'];

      $current_week = $_REQUEST['search_time_week'];

      

&#63;>

<style>

#search_type{float:left}

#searchtype_day{float:left}

#searchtype_week{float:left}

#searchtype_month{float:left}

  

  

</style>

<body>

  <select name="search_type" id="search_type" >

         <option value="day" >按照天统计</option>

         <option value="week" >按照周统计</option>

         <option value="month">按照月统计</option>

    </select>

    <div class="w140" id="searchtype_day">

      <div class='input-group date' id='datetimepicker1'

        <input id="stime" class="form-control" type="text" value="<&#63;php echo $search_time;&#63;>" name="search_time">

        <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>

      </div>

    </div> 

     <div id="searchtype_week" style="display:none;">

        <select name="search_time_year" id="searchweek_year">

          <&#63;php foreach ($year_arr as $k=>$v){&#63;>

          <option value="<&#63;php echo $k;&#63;>" <&#63;php echo $current_year == $k&#63;'selected':'';&#63;>><&#63;php echo $v; &#63;></option>

          <&#63;php } &#63;>

        </select>

        <select name="search_time_month" id="searchweek_mouth">

          <&#63;php foreach ($month_arr as $k=>$v){&#63;>

          <option value="<&#63;php echo $k;&#63;>" <&#63;php echo $current_month == $k&#63;'selected':'';&#63;>><&#63;php echo $v; &#63;></option>

          <&#63;php } &#63;>

        </select>

        <select name="search_time_week" id="searchweek_week">

          <&#63;php foreach ($week_arr as $k=>$v){&#63;>

          <option value="<&#63;php echo $v['key'];&#63;>" <&#63;php echo $current_week == $v['key']&#63;'selected':'';&#63;> ><&#63;php echo $v['val']; &#63;></option>

          <&#63;php } &#63;>

        </select>

       </div>

      

      <div id="searchtype_month" style="display:none;">

          <select name="search_time_year" class="querySelect">

          <&#63;php foreach ($year_arr as $k=>$v){&#63;>

          <option value="<&#63;php echo $k;&#63;>" <&#63;php echo $current_year == $k&#63;'selected':'';&#63;> ><&#63;php echo $v; &#63;></option>

          <&#63;php } &#63;>

        </select>

        <select name="search_time_month" class="querySelect">

          <&#63;php foreach ($month_arr as $k=>$v){&#63;>

          <option value="<&#63;php echo $k;&#63;>" <&#63;php echo $current_month == $k&#63;'selected':'';&#63;>><&#63;php echo $v; &#63;></option>

          <&#63;php } &#63;>

        </select>

      </div>

   <div id="line_chart" style="width:600px;height:400px;"></div>

   <&#63;php $thearray=array(11,11,15,13,12,13,10);&#63;>

   <script type="text/javascript">

    // 基于准备好的dom,初始化echarts实例

  

    var mylineChart=echarts.init(document.getElementById('line_chart'));

  

    option1 = {

  title: {

    text: '未来一周气温变化',

    subtext: '纯属虚构'

  },

  tooltip: {

    trigger: 'axis'

  },

  legend: {

    data:['最高气温','最低气温']

  },

  toolbox: {

    show: true,

    feature: {

      dataZoom: {},

      // dataView: {readOnly: false},

      magicType: {type: ['line', 'bar']},

      restore: {},

      saveAsImage: {}

    }

  },

  xAxis: {

    type: 'category',

    boundaryGap: false,

    data: ['周一','周二','周三','周四','周五','周六','周日']

  },

  yAxis: {

    type: 'value',

    axisLabel: {

      formatter: '{value} °C'

    }

  },

  series: [

    {

      name:'最高气温',

      type:'line',

      data:<&#63;php echo(json_encode($thearray)); &#63;>,

      markPoint: {

        data: [

          {type: 'max', name: '最大值'},

          {type: 'min', name: '最小值'}

        ]

      },

      markLine: {

        data: [

          {type: 'average', name: '平均值'}

        ]

      }

    },

    {

      name:'最低气温',

      type:'line',

      data:[1, 4, 2, 5, 3, 2, 0],

      markPoint: {

        data: [

          {name: '周最低', value: -2, xAxis: 1, yAxis: -1.5}

        ]

      },

      markLine: {

        data: [

          {type: 'average', name: '平均值'}

        ]

      }

    }

  ]

};

    // 使用刚指定的配置项和数据显示图表。

    mylineChart.setOption(option1);

  </script>

  <script>

  //展示搜索时间框

function show_searchtime(){

  s_type = $("#search_type").val();

  $("[id^='searchtype_']").hide();

  $("#searchtype_"+s_type).show();

}

  $(function(){

     

    show_searchtime();

  $("#search_type").change(function(){

    show_searchtime();

  });

     

  //更新周数组

  $("[name='search_time_month']").change(function(){

    

    var year = $("[name='search_time_year']").val();

    var month = $("[name='search_time_month']").val();

  

    $("[name='search_time_week']").empty();

    $.getJSON('php/ajax.php',{y:year,m:month},function(data){

      if(data != null){

        for(var i = 0; i < data.length; i++) {

          $("[name='search_time_week']").append('<option value="'+data[i].key+'">'+data[i].val+'</option>');

        }

      }

    });

  });

  //更新年数组

    $("[name='search_time_year']").change(function(){

    var year = $("[name='search_time_year']").val();

      

    $("[name='search_time_week']").empty();

    $("#searchweek_mouth option:first").prop("selected", 'selected');

    $.getJSON('php/ajax.php',{y:year},function(data){

      if(data != null){

        for(var i = 0; i < data.length; i++) {

          $("[name='search_time_week']").append('<option value="'+data[i].key+'">'+data[i].val+'</option>');        

        }

          

      }

    });

  });

    

  });

  

   

  </script>

</body>

</html>

Copy after login

5.time_deal.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

<&#63;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;

}

  

  /**

   * 处理搜索时间

   */

  public function dealwithSearchTime($search_arr){

    //初始化时间

    //天

    if(!$search_arr['search_time']){

      $search_arr['search_time'] = date('Y-m-d', time()- 86400);

    }

    $search_arr['day']['search_time'] = strtotime($search_arr['search_time']);//搜索的时间

    

    //周

    if(!$search_arr['searchweek_year']){

      $search_arr['searchweek_year'] = date('Y', time());

    }

    if(!$search_arr['searchweek_month']){

      $search_arr['searchweek_month'] = date('m', time());

    }

    if(!$search_arr['searchweek_week']){

      $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(time()));

    }

    $weekcurrent_year = $search_arr['searchweek_year'];

    $weekcurrent_month = $search_arr['searchweek_month'];

    $weekcurrent_week = $search_arr['searchweek_week'];

    $search_arr['week']['current_year'] = $weekcurrent_year;

    $search_arr['week']['current_month'] = $weekcurrent_month;

    $search_arr['week']['current_week'] = $weekcurrent_week;

    

    //月

    if(!$search_arr['searchmonth_year']){

      $search_arr['searchmonth_year'] = date('Y', time());

    }

    if(!$search_arr['searchmonth_month']){

      $search_arr['searchmonth_month'] = date('m', time());

    }

    $monthcurrent_year = $search_arr['searchmonth_year'];

    $monthcurrent_month = $search_arr['searchmonth_month'];

    $search_arr['month']['current_year'] = $monthcurrent_year;

    $search_arr['month']['current_month'] = $monthcurrent_month;

    return $search_arr;

  }

Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone’s study.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125250.htmlTechArticlephp implements the search box for querying by days, weeks, and months. The example of php days in this article shares with everyone the php implementation button Search box for day, week, month query, display data statistics when searching...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

PHP's Current Status: A Look at Web Development Trends PHP's Current Status: A Look at Web Development Trends Apr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

PHP: The Foundation of Many Websites PHP: The Foundation of Many Websites Apr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

See all articles