Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help inputing DB values into calendar.

Status
Not open for further replies.

dexthageek

IS-IT--Management
Mar 23, 2002
59
0
0
US
I have come across a great calendar script however, im having a hard time trying to figure out how to input my DB records to the proper dates in the calendar.

Here is the code.
Code:
<?php

$today=date(Ymd);
$calMonth=$_GET[calMonth];
$calYear=$_GET[calYear];

if ((!$calMonth) && (!$calYear)) {
$calMonth = date ("m");
$calYear = date ("Y");
}

$monthlydate=$calYear.$calMonth."00";
$ThisMonth=$calYear . $calMonth;
$ThisMonth=($ThisMonth*100);

//  Calculate the viewed Month.
$Timestamp = mktime (0, 0, 0, $calMonth, 1, $calYear);
$MonthName  =  date("F", $Timestamp);

//  Make a table with the proper month.
print ("<P ALIGN=LEFT><TABLE BORDER=0 CELLPADDING=1 WIDTH=97% CELLSPACING=0 BGCOLOR=BLACK ALIGN=CENTER><tr><td><TABLE BORDER=0 CELLPADDING=2 WIDTH=100% CELLSPACING=1 ALIGN=CENTER><TR BGCOLOR=BLACK><TD ALIGN=CENTER COLSPAN=7><FONT SIZE=4 COLOR=WHITE><B>$MonthName $calYear</B></FONT></TD></TR><TR BGCOLOR=BLACK><TD ALIGN=CENTER WIDTH=15%><B><FONT SIZE=2 COLOR=WHITE>Sun</FONT></B></TD><TD ALIGN=CENTER WIDTH=14%><B><FONT SIZE=2 COLOR=WHITE>Mon</FONT></B></TD><TD ALIGN=CENTER WIDTH=14%><B><FONT SIZE=2 COLOR=WHITE>Tue</FONT></B></TD><TD ALIGN=CENTER WIDTH=14%><B><FONT SIZE=2 COLOR=WHITE>Wed</FONT></B></TD><TD ALIGN=CENTER WIDTH=14%><B><FONT SIZE=2 COLOR=WHITE>Thu</FONT></B></TD><TD ALIGN=CENTER WIDTH=14%><B><FONT SIZE=2 COLOR=WHITE>Fri</FONT></B></TD><TD ALIGN=CENTER WIDTH=15%><B><FONT SIZE=2 COLOR=WHITE>Sat</FONT></B></TD></TR>\n");

$MonthStart = date("w", $Timestamp);
if ($MonthStart == 0) {
$MonthStart = 7;
}
$LastDay = date("d", mktime (0, 0, 0, $calMonth+1, 0, $Year));
$calStartDate = -$MonthStart;
for ($k = 1; $k <= 6; $k++) {

//SET 6 ROWS
print ("<TR BGCOLOR=WHITE>");
for ($i = 1; $i <= 7; $i++) {

//SET 7 COLUMNS
$calStartDate++;
if (($calStartDate <= 0) || ($calStartDate > $LastDay)) {
print ("<TD BGCOLOR=#DDDDDD height=110 valign=top align=left>&nbsp</TD>");
} elseif (($calStartDate >= 1) && ($calStartDate <= $LastDay)) {

//IF TODAY
if ($calStartDate<"10") {$MyDay="0$calStartDate";} else {$MyDay="$calStartDate";}

$ThisDay="$calYear$calMonth$MyDay";
if (($MyDay==date("d")) AND ($calMonth==date("m")) AND ($calYear==date("Y"))) {
print ("<TD BGCOLOR=#FFCCCC height=110 valign=top align=left><FONT SIZE=2><b>$calStartDate</b></font>\n");
} else {
print ("<TD height=110 valign=top align=left><FONT SIZE=2><b>$calStartDate</b></font>\n");
}

print ("</TD>");
}
}
print ("</TR>\n");
}
print ("</TABLE></td></tr><TR BGCOLOR=WHITE><TD>\n");

// Make the form.
print ("<FORM METHOD=GET>\n");
print ("Select another month to view:\n");
print ("<SELECT NAME=calMonth>\n");
if ($calMonth=="12") { print ("<OPTION SELECTED VALUE=01>January</OPTION>\n"); } else { print ("<OPTION VALUE=01>January</OPTION>\n"); }
if ($calMonth=="01") { print ("<OPTION SELECTED VALUE=02>February</OPTION>\n");} else { print ("<OPTION VALUE=02>February</OPTION>\n"); }
if ($calMonth=="02") { print ("<OPTION SELECTED VALUE=03>March</OPTION>\n"); } else { print ("<OPTION VALUE=03>March</OPTION>\n"); }
if ($calMonth=="03") { print ("<OPTION SELECTED VALUE=04>April</OPTION>\n"); } else { print ("<OPTION VALUE=04>April</OPTION>\n"); }
if ($calMonth=="04") { print ("<OPTION SELECTED VALUE=05>May</OPTION>\n"); } else { print ("<OPTION VALUE=05>May</OPTION>\n"); }
if ($calMonth=="05") { print ("<OPTION SELECTED VALUE=06>June</OPTION>\n"); } else { print ("<OPTION VALUE=06>June</OPTION>\n"); }
if ($calMonth=="06") { print ("<OPTION SELECTED VALUE=07>July</OPTION>\n"); } else { print ("<OPTION VALUE=07>July</OPTION>\n"); }
if ($calMonth=="07") { print ("<OPTION SELECTED VALUE=08>August</OPTION>\n"); } else { print ("<OPTION VALUE=08>August</OPTION>\n"); }
if ($calMonth=="08") { print ("<OPTION SELECTED VALUE=09>September</OPTION>\n"); } else { print ("<OPTION VALUE=09>September</OPTION>\n"); }
if ($calMonth=="09") { print ("<OPTION SELECTED VALUE=10>October</OPTION>\n"); } else { print ("<OPTION VALUE=10>October</OPTION>\n"); }
if ($calMonth=="10") { print ("<OPTION SELECTED VALUE=11>November</OPTION>\n"); } else { print ("<OPTION VALUE=11>November</OPTION>\n"); }
if ($calMonth=="11") { print ("<OPTION SELECTED VALUE=12>December</OPTION>\n"); } else { print ("<OPTION VALUE=12>December</OPTION>\n"); }
print ("</SELECT>\n");
print ("<SELECT NAME=calYear>\n");

$MyNextYear=$calYear+1;
$ThisYear=date("Y");
if ($calMonth=="12") {
print ("<OPTION SELECTED VALUE=$MyNextYear>$MyNextYear</OPTION>\n");
} else {
print ("<OPTION SELECTED VALUE=$calYear>$calYear</OPTION>\n");
}

for ($nextyear = $ThisYear; $nextyear <= 2015; $nextyear++) {
print ("<OPTION VALUE=$nextyear>$nextyear</OPTION>\n");
}

print ("</SELECT><INPUT TYPE=SUBMIT NAME=SUBMIT VALUE=\"Display\"></FORM></TD></TR></TABLE></P>\n");
?>

Thanks in Advance
Mike

 
spencertaylor said:
This code appears to ignore leap years and makes every year a leap year?!?!

This is due to an undefined variable. See the line:
Code:
$LastDay = date("d", mktime (0, 0, 0, $calMonth+1, 0, $Year));

There is no such thing as $Year. This should be changed to $calYear.

- - picklefish - -
Why is everyone in this forum responding to me as picklefish?
 
Yep, that fixed it.

I'd have noticed that if I'd tried to look through it for long enough, honest guvnor ;o)

Also, I've stripped out all the html from print statements and inserted db code in the relevant places. Works fine and it's quick too!

Cheers for the starting point jimoblak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top