Blog calendar implementation code in php

Source: Internet
Author: User
The blog calendar implementation code in php shares a blog calendar implementation code in php. it is very easy to query the database, as long as you modify the field name to be the same as that in your database, the instance code is as follows:

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. ='. $ Uid. '& starttime = '. $ blogs [$ cur] ['Dateline ']. '& endtime = '. ($ blogs [$ cur] ['Dateline '] + 86400 ). '"title = "'. $ blogs [$ cur] ['num']. '">'. $ 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.