This article mainly introduces related information about the search box for php query by days, weeks, and months, you can refer to the examples in this article to share the search box for php to query by days, weeks, and months. The statistical charts of data are displayed during the search, mainly displaying the graphic effect, for your reference, the specific content is as follows:
1. ajax. php
<? 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;/*** get the weekly array of the system for a month, if the first week is insufficient, you must add ** @ param int $ current_year * @ param int $ current_month * @ return string [] [] */function getMonthWeekArr ($ current_year, $ current_month) {// The first day of the month $ firstday = strtotime ($ current_year. '-'. $ current_month. '-01'); // There are several days in the first week of the month $ firstweekday = (7-date ('N', $ firstday) + 1 ); // calculate the time of the first Monday of the month $ starttime = $ firstday-3600 * 24 * (7-$ firstweekday); // The last day of the month $ lastday = strtotime ($ current_year. '-'. $ current_month. '-01 '. "+ 1 month-1 day"); // There are several days in the last week of the month $ lastweekday = date ('N', $ lastday ); // time of the last weekend of the month $ endtime = $ lastday-3600 * 24 * ($ lastweekday % 7); $ step = 3600*24*7; // Step value $ week_arr = array (); for ($ I = $ starttime; $ I <$ endtime; $ I = $ I + 3600*24*7) {$ week_a Rr [] = 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
<? Php // Obtain the system year array/***** @ return string [] */function getSystemYearArr () {$ year_arr = array ('20140901' => '20160901 ', '20140901' => '20160901', '20160901' => '20160901', '20160901' => '20160301 ', '20140901' => '20160901', '20160901' => '20160901', '20160901' => '20160301 ', '20180101' => '20180101', '20180101' => '20180101'); return $ year_arr ;} /*** obtain the system month array ** @ 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;}/*** obtain the system Weekly array ** @ return string [] */function getSystemWeekArr () {$ week_arr = array ('1' => 'Monday', '2' => 'Tuesday', '3' => 'weday ', '4' => 'thurs', '5' => 'Friday', '6' => 'satur', '7' => 'Sunday '); return $ week_arr;}/*** get the last day of a month ** @ param int $ year * @ param int $ month * @ return number */function getMonthLastDay ($ year, $ month) {$ t = m Ktime (0, 0, 0, $ month + 1, 1, $ year); $ t = $ t-60*60*24; return $ t ;} /*** obtain the weekly array of the system for a month, if the first week is insufficient, you must add ** @ param int $ current_year * @ param int $ current_month * @ return string [] [] */function getMonthWeekArr ($ current_year, $ current_month) {// The first day of the month $ firstday = strtotime ($ current_year. '-'. $ current_month. '-01'); // There are several days in the first week of the month $ firstweekday = (7-date ('N', $ firstday) + 1 ); // calculate the time of the first Monday of the month $ starttime = $ fir Stday-3600 * 24 * (7-$ firstweekday); // The last day of the month $ lastday = strtotime ($ current_year. '-'. $ current_month. '-01 '. "+ 1 month-1 day"); // There are several days in the last week of the month $ lastweekday = date ('N', $ lastday ); // time of the last weekend of the month $ endtime = $ lastday-3600 * 24 * ($ lastweekday % 7); $ step = 3600*24*7; // Step value $ 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*2 4*6), 'Val' => date ('Y-m-D', $ I ).'~ '. Date ('Y-m-D', $ I + 3600*24*6);} return $ week_arr ;} /*** processing search time */function dealwithSearchTime ($ search_arr = '') {// initialization time/day 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']); // search Time // week 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; // month 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;}/*** get the start time and end time of the week ** @ 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 ['update'] = date ('Y-m-D ', $ current_time + 86400 * (7-date ('N', $ current_time); return $ return_arr;}/*** query the weekly array of each month */function getweekofmonth () {$ year = $ _ GET ['Y']; $ month = $ _ GET ['M']; $ week_arr = getMonthWeekArr ($ year, $ month ); echo json_encode ($ week_arr); die ;}
3. statistics. php
<? Php/*** Statistics ** @ abstract ** @ copyright Grisi, 2016 ** @ author liujun ** @ version Id: statics v1.0 2016/2/5 * // *** obtain the chart data ** param $ statarr required for the chart * @ return string */function getStatData_LineLabels ($ stat_arr) {// chart area, graphic area, and general chart configuration options $ stat_arr ['chart'] ['type'] = 'line '; // Chart sequence color array $ stat_arr ['Colors ']? '': $ Stat_arr ['Colors '] = array (' # 058dc7', '# ED561B', '#8bbc21', '# 0d233a '); // Remove copyright information $ stat_arr ['credit'] ['enabled'] = false; // export function options $ stat_arr ['porting'] ['enabled'] = false; // if the title is a string, use the default style is_string ($ stat_arr ['title'])? $ Stat_arr ['title'] = array ('text' =>"{$ Stat_arr ['title']}", 'X' =>-20):''; // if the sub-title is a string, use the default style is_string ($ stat_arr ['subtitle'])? $ Stat_arr ['subtitle'] = array ('text' =>"{$ Stat_arr ['subtitle']}", 'X' =>-20):''; // if the y axis is a string, use the default style 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 );} /*** obtain Column2D statistical chart data ** @ param array $ stat_arr * @ return string */function getStatData_Column2D ($ stat_arr) {// chart area, graphic area, and general chart configuration options $ stat_arr ['chart'] ['type'] = 'column '; // Remove copyright information $ stat_arr ['credit'] [ 'Enabled'] = false; // export function options $ stat_arr ['porting'] ['enabled'] = false; // if the title is a string, use the default style is_string ($ stat_arr ['title'])? $ Stat_arr ['title'] = array ('text' =>"{$ Stat_arr ['title']}", 'X' =>-20):''; // if the sub-title is a string, use the default style is_string ($ stat_arr ['subtitle'])? $ Stat_arr ['subtitle'] = array ('text' =>"{$ Stat_arr ['subtitle']}", 'X' =>-20):''; // if the y axis is a string, use the default style if (is_string ($ stat_arr ['yaxis ']). {$ text = $ stat_arr ['yaxis ']; unset ($ stat_arr ['yaxis']); $ stat_arr ['yaxis '] ['title'] ['text'] = $ text;} // array of bar colors $ color = array (' #7a96a4 ', '# cba952', '#667b6', '# a26824',' #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);}/*** obtain Basicbar statistical chart data ** @ param array $ stat_arr * @ return string */function getStatData_Basicbar ($ stat_arr) {// chart area, graphic area, and general chart configuration options $ stat_arr ['chart'] ['typ E '] = 'bar'; // Remove copyright information $ stat_arr ['credit'] ['enabled'] = false; // export function options $ stat_arr ['porting'] ['enabled'] = false; // Display datalabel $ stat_arr ['plotoptions '] ['bar'] ['datalabels'] ['enabled'] = true; // if the title is a string, use the default style is_string ($ stat_arr ['title'])? $ Stat_arr ['title'] = array ('text' =>"{$ Stat_arr ['title']}", 'X' =>-20):''; // if the sub-title is a string, use the default style is_string ($ stat_arr ['subtitle'])? $ Stat_arr ['subtitle'] = array ('text' =>"{$ Stat_arr ['subtitle']}", 'X' =>-20):''; // if the y axis is a string, use the default style if (is_string ($ stat_arr ['yaxis ']). {$ text = $ stat_arr ['yaxis ']; unset ($ stat_arr ['yaxis']); $ stat_arr ['yaxis '] ['title'] ['text'] = $ text;} // array of bar colors $ color = array (' #7a96a4 ', '# cba952', '#667b6', '# a26824',' #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);}/*** calculate the period-over-period ** @ 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 ;} /*** computing YoY ** @ 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 ;} /*** map statistical chart ** @ 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 );} /*** get pie chart data ** @ param array $ data * @ return string */function getStatData_Pie ($ data) {$ stat_arr ['chart'] ['type'] = 'Pie'; $ stat_arr ['credit'] ['enabled'] = false; $ stat_arr ['title'] ['text'] = $ data ['title']; $ stat_arr ['tooltip '] ['pointformat'] =' {series. name }:{Point. y}'; $ Stat_arr ['plotoptions'] ['pie'] = array ('allowpointselect' => true, 'cursor '=> 'pointer ', 'datalabels' => array ('enabled' => $ data ['label _ Show'], 'color' => '#000000 ', 'ororcolor' => '#000000', 'format' =>'{Point. name}: {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 );}
4. theline. php
Echarts