Maison > développement back-end > tutoriel php > 下面的函数按月调用数据怎么改成按年调用数据

下面的函数按月调用数据怎么改成按年调用数据

WBOY
Libérer: 2016-06-23 13:27:14
original
848 Les gens l'ont consulté

下面的函数按月调用数据怎么改成按年调用数据

	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年m月');			$partitions[$min_time]['min_date'] = $min_time;			$partitions[$min_time]['max_date'] = $max_time;			$partitions[$min_time]['where'] = $where;			$index++;		}		krsort($partitions);		return $partitions;	}}
Copier après la connexion


前台的调用代码是这样的:

他的下拉菜单选择都是每个月的所有过期数据,我要的效果是下拉菜单加一个全部过期数据或每年份的过期数据


回复讨论(解决方案)

小弟不怎么懂PHP,知道的大哥直接给代码可以吗?谢谢了

没人帮忙吗???????

    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年m月');            $partitions[$min_time]['min_date'] = $min_time;            $partitions[$min_time]['max_date'] = $max_time;            $partitions[$min_time]['where'] = $where;            $index++;        }        krsort($partitions);        return $partitions;    }
Copier après la connexion

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal