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 strongm 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
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

 
Yea I know that is how the copy and paste came out. Trust me I have it indented in my code.
 
in dexthageek we trust, or was that in trance we trust?

btw. when using selected, type it like this:
Code:
selected="selected"

also:
Code:
checked="checked"

if you only use the checked or selected, it might not work in all browsers!

also write the html in lowercase, not UPPERCASE.

AND = &&...

eg.
if ((1 < 2) && ("a" != "b"))
{
echo "wtf?";
}

Olav Alexander Mjelde
Admin & Webmaster
 
I didnt write this script its one i found on this site last week. It seems to be working good at the moment, I have made various improvments to it since I sent that first post.

Thanks for the info

Mike
 
selected="selected" and checked="checked" do not change over browsers; selected (no =) is invalid XHTML. Use selected="selected" for XHTML pages.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
if you only use the checked or selected, it might not work in all browsers!

This is not true; it will not work in all Doctypes.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
There are three HTML 4.0.1 doctypes:

HTML Transitional
HTML Strict
HTML Frameset

There are three XHTML 1.0 doctypes:

XHTML Transitional
XHTML Strict
XHTML Frameset

If the doctype on your page is one of the XHTML doctypes, your page will not validate through the W3C Validator if it includes selected, not selected="selected". However, if you are using one of the HTML doctypes, your page will validate. See for more information.

This is browser-independent.

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
chessbot: if some tags are missing or incompatible, they might not work as expected.

eg. iframe needs both id and name, or it will not work on both IE and Netscape!

(for target)

The reason it does not validate, is that it's not a "standard" way of coding, which then might cause some strange effects.

I had some problems on a php/mysql page, where some members got all info about themself set to "" in all fields except those which could not be updated by the users.

I did not understand why this happend and I figured it out, that there where some typo in one of the form tags.

this tag then corrupted everything else.

it did not happend in IE or Netscape, but in some more rare browsers.

ps. I know that the example above is not a typo, but nevertheless, I've heard about people having problems using pages where it does not have selected="selected".

Olav Alexander Mjelde
Admin & Webmaster
 
yea that is a good calander script. how would you go about putting different information in for different dates??

e.g. october 30 - football match

any ideas??


Regards,

Martin

Gaming Help And Info:
 
Well, As far as I can see from the code above, there is no reference to any database fields.

You simply insert into a table, in fields and set the date to the chosen date (chosen by user in GUI).

for further comments, I would have to see database structure and some more code maybe.

Olav Alexander Mjelde
Admin & Webmaster
 
Here is the code I used to add my database values to the calendar.

First I placed my db values into an array called $CalDate[] and then ran a while loop to display all calendar events that matched the
$ThisDay variable with the date column from my database.

Code:
$ThisDay="$calYear$calMonth$MyDay";
if (($MyDay==date("d")) || ($calMonth==date("m")) || ($calYear==date("Y"))) {

$data = $db->query("SELECT *, 
                    DATE_FORMAT(start_date, '%b %e, %Y') AS formated_date FROM events WHERE start_date = '.$ThisDay.'                   AND (school LIKE '%Wanamassa%' OR school LIKE '%All%')");

print ("<TD BGCOLOR=#FFCCCC height=110 valign=top align=left class=calendar><FONT SIZE=2><b>$calStartDate</b></font><br>");

while ($calDate = mysql_fetch_array($data)) { print ("<p class=calendar><a href=\"./cal_details.php?id=$calDate[id]\">$calDate[name]</a></p>\n"); }
 
I have an "end_date" value in my db but i have not added it to the calendar yet. I hate working with dates, and I have more projects im working on so I will work on that at a later date.

If anyone else knows how to do that let me know. I would love for the calendar to automatically input the date ranges.

my db values are "start_date" and "end_date"

thanks

Mike
 
DaButcher said:
good thing you did, cause this code looks like hell!
identing is an nice invention!

This calendar code looks very familiar. I am to blame for the code. The clumsy formatting is simply my own job security. [bigsmile] I also swapped some text out to conceal the database interaction.

This code appears several times in this forum and more recent versions show corrections. The calendar script can be seen in action at
If I find time, I will see if I can dig up a cleaner, current version of this code. This is messy. What thread did you find this in?

- - picklefish - -
Why is everyone in this forum responding to me as picklefish?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top