How to change the following function call data by month to call data by year? how to change the function call data by month to call data by year?
Public function getGoodsPartitions () {$ now_time = gmtTime (); $ date = D ('Goods ')-> min ('end _ time '); $ min_year = toDate ($ date, 'y'); $ min_month = toDate ($ date, 'M'); $ max_year = toDate ($ now_time, 'y '); $ max_month = toDate ($ now_time, 'M'); $ time_arr = array (); $ partitions = array (); for ($ year = $ min_year; $ year <= $ max_year; $ year ++) {$ mmonth = 12; $ month = 1; if ($ year = $ max_year) $ mmonth = $ max_month; if ($ year = $ min_year) $ month = $ min_month; for ($ month; $ month <= $ mmonth; $ month ++) {$ next_year = $ year; $ next_month = $ month + 1; if ($ month = 12) {$ next_year ++; $ next_month = 1 ;}$ time_arr [localStrToTime ($ year. '-'. $ month. '-01 00:00:00')] = localStrToTime ($ next_year. '-'. $ next_month. '-01 00:00:00') ;}}$ index = 1; $ count = count ($ time_arr); foreach ($ time_arr as $ min_time => $ max_time) {if ($ max_time> $ now_time) $ max_time = $ now_time; $ where = "gk. end_time> = $ min_time AND gk. end_time <$ max_time "; $ partitions [$ min_time] ['Date'] = toDate ($ min_time, 'Y-mmonth '); $ partitions [$ min_time] ['min _ date'] = $ min_time; $ partitions [$ min_time] ['max _ date'] = $ max_time; $ partitions [$ min_time] ['where'] = $ where; $ index ++;} krsort ($ partitions); return $ partitions ;}}
The front-end call code is as follows:
Selected>{$ Partition. date}
All the expired data of each month is selected from the drop-down menu. I want to add all expired data or expired data of each year to the drop-down menu.
Reply to discussion (solution)
The younger brother doesn't know much about PHP. can he give the code directly? Thank you.
No one can help you ???????
Public function getGoodsPartitions () {$ now_time = gmtTime (); $ date = D ('Goods ')-> min ('end _ time '); $ min_year = toDate ($ date, 'y'); $ max_year = toDate ($ now_time, 'y'); $ time_arr = array (); $ partitions = array (); for ($ year = $ min_year; $ year <= $ max_year; $ year ++) {$ time_arr [localStrToTime ($ year. '-01-01 00:00:00')] = localStrToTime ($ next_year. '-01-01 00:00:00');} $ index = 1; $ count = count ($ time_arr); foreach ($ time_arr as $ min_time => $ max_time) {if ($ max_time> $ now_time) $ max_time = $ now_time; $ where = "gk. end_time> = $ min_time AND gk. end_time <$ max_time "; $ partitions [$ min_time] ['Date'] = toDate ($ min_time, 'Y-mmonth '); $ partitions [$ min_time] ['min _ date'] = $ min_time; $ partitions [$ min_time] ['max _ date'] = $ max_time; $ partitions [$ min_time] ['where'] = $ where; $ index ++;} krsort ($ partitions); return $ partitions ;}