Implement the Calendar function in PHP for blog Calendar problems

Source: Internet
Author: User
The following is the implementation code. if you forget where the code was obtained, it may be Discuz! The personal space is now posted to share with you the following implementation code. if you forget where to find the code, it is probably Discuz! In the personal space
Now post it for everyone to share




Function calendarnew ($ starttime = 0 ){
Global $ db, $ tablepre, $ timestamp, $ site_timeoffset, $ site_dateformat, $ curtime;


$ Starttime = $ starttime? $ Starttime: $ timestamp;
$ Curtime = gmdate ($ site_dateformat, $ starttime + $ timeoffset * 3600 );


$ Pendtime = $ starttime-(gmdate ('J', $ starttime + $ timeoffset * 3600)-1) * 86400-($ starttime + $ timeoffset * 3600) % 86400;
$ Pstarttime = $ pendtime-gmdate ('t', $ pendtime + $ timeoffset * 3600-1) * 86400;


$ Nstarttime = $ pendtime + gmdate ('t', $ pendtime + $ timeoffset * 3600 + 1) * 86400;
$ Nendtime = $ nstarttime + gmdate ('t', $ nstarttime + $ timeoffset * 3600 + 1) * 86400;


List ($ skip, $ dim) = explode ('-', gmdate ('W-t', $ pendtime + $ timeoffset * 3600 + 1 ));
$ Rows = ceil ($ skip + $ dim)/7 );


$ Blogs = array ();
$ Query = $ db-> query ("SELECT dateline FROM {$ tablepre} vitaitems WHERE dateline BETWEEN '$ pendtime' AND '$ nstarttime '");
While ($ blog = $ db-> fetch_array ($ query )){
$ Day = gmdate ('J', $ blog ['Dateline '] + $ timeoffset X 3600 );
! Isset ($ blogs [$ day])? $ Blogs [$ day] = array ('num' => 1, 'Dateline '=> $ blog ['Dateline']-$ blog ['Dateline '] % 86400 ): $ blogs [$ day] ['num'] ++;
}
$ Cal = '';
For ($ row = 0; $ row <$ rows; $ row ++ ){
$ Cal. ='';
For ($ col = 0; $ col <7; $ col ++ ){
$ Cur = $ row * 7 + $ col-$ skip + 1;
$ Curtd = $ row * 7 + $ col <$ skip | $ cur> $ dim? '': $ Cur;
If (! Isset ($ blogs [$ cur]) {
$ Cal. =''. $ Curtd .'';
} Else {
$ Cal. =' '. $ Cur .'';
}
}
$ Cal. = '';
}
Return $ cal;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.