Php code _ PHP Tutorial for adding a calendar to a blog

Source: Internet
Author: User
Add the php code for the calendar in the blog. Do you want to add a calendar to your blog by adding the php code for adding a calendar? Blue1000 is here to share with you a simple PHP blog calendar implementation code. if you need it, refer to the php code for adding a calendar in a blog.

Do you want to add a calendar in your blog? Blue1000 is here to share with you a simple PHP blog calendar implementation code. if you need it, please refer to it. it is very easy to query the database, you just need to modify the field name to be the same as your database.

The 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. = ''. $ cur .'';

}

}

$ Cal. = '';

}

Return $ cal;

}

Do you want to add a calendar in your blog? Blue1000 is here to share with you a simple PHP blog calendar implementation code. if you need it, please refer to I...

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.