PHP Calendar Sign-in module

Source: Internet
Author: User

Create Table

CREATE TABLE ' Tb_signinfo ' (
' id ' int (ten) unsigned not NULL auto_increment COMMENT ' record each check-in details ',
' MemberID ' int (one) DEFAULT NULL COMMENT ' Association member table ID ',
' SignDate ' int (8) DEFAULT NULL COMMENT ' record check-in date, format: Year Month Day ',
' Credit ' int (255) The default NULL COMMENT ' record the value of the points that are given to each check-in ',
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=17 DEFAULT Charset=utf8

<style type= "Text/css" >
#tc_calendar {width:100%;}
#tc_title {Height:33px;line-height:33px;text-align:right;overflow:hidden;}
#tc_title strong{font-weight:bold;font-size:14px;}
#tc_calendar {border-collapse:collapse;}
#tc_calendar Td{text-align:center;width:35px;height:20px;line-height:20px;background-color: #efefef; border-bottom:1px solid #fff; border-right:1px solid #fff;}
#tc_calendar. Even td{background-color: #e6e6e6;}
#tc_calendar TD. Current2{display:block;background-color: #f60; color: #fff;}
#tc_calendar. Current{background-color: #cf0!important;color: #000;}
#tc_calendar. Current2{background-color: #f60!important;color: #000;}
#tc_week td{color: #fff; Background-color: #373737;}
</style>
<?php
$mdays =date ("T"); Total days of the month
$datenow =date ("J"); Date of day
$monthnow =date ("n"); Month of the Month
$yearnow =date ("Y"); Year of the Year
Calculate the first day of the month is the days of the week
$wk 1st=date ("W", Mktime (0,0,0, $monthnow, 1, $yearnow));
$trnum =ceil (($mdays + $wk 1st)/7); Calculate the number of table rows
Here is the table string
$tabstr = "<table id=tc_calendar><tr id=tc_week><td> Day </td><td> a </td><td> Two </td><td> three </td><td> four </td><td> five </td><td> six </td></tr > ";
for ($i =0; $i < $trnum; $i + +) {
$tabstr. = "<tr class=" even ">";
for ($k =0; $k <7; $k + +) {//seven cells per line
$tabidx = $i *7+ $k; Get the cell itself ordinal
If the cell ordinal is less than the number of days of the first day of the month ($wk 1st) or greater (total number of months + $WK 1st)
Fill in the blanks only, and vice versa, write the date
($tabidx < $wk 1st or $tabidx > $mdays + $wk 1st-1)? $dayecho = "a": $dayecho = $tabidx-$wk 1st+1;
Assembled date
if ($monthnow <10) {$m = "0". $monthnow;} else{$m = $monthnow;};
if ($dayecho <10) {$d = "0". $dayecho;} else{$d = $dayecho;};
$ymd = $yearnow. $m. $d;
The date information after assembling is compared with the database. Database date format 20150611
I'm using the CI framework here.
$sql = "Select SignDate from Tb_signinfo where signdate= '". $ymd. "'";
$result = $this->db->query ($sql)->num_rows;
if ($result! = 0) {
$TODAYBG = "class=" Current2 "";
}
Else
{
$TODAYBG = "";
}
Highlighted here today's date with the above check-in display code is repeated, if you need two effects at the same time to implement, self-processing judgment statement can be
/*if ($dayecho = = $datenow) {
$TODAYBG = "class=" Current2 "";
}
Else
{
$TODAYBG = "";
}*/
$tabstr. = "<td". $todaybg. " > $dayecho </td> ";
}
$tabstr. = "</tr>";
}
$tabstr. = "</table>";
?>
<div id= "Tc_calendardiv" ><div id= "Tc_title" ><strong><?= $yearnow?> year <?= $monthnow?> Month </strong></div>
<?php echo $tabstr;? >
</div>

PHP Calendar Sign-in module

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.