Jump to content

calendar


chriscloyd

Recommended Posts

im trying to create a calendar where it shows a calendar on this page cloydfamily.com/index.php?module=calendar and then an admin page where i can enter an event on a specific date how could i go about doing this and i could help u guys with free webhosting if u guys help me
Link to comment
Share on other sites

Yes, I know how to do calendars.

But then it would be I did instead of one your friend did - what's the difference?

Anyway, I take it the answer is database and not flat file.

You need to create an input form for the data you want to store and a table to store the data.

Something like

Event table
---------------
eventID INT (PK)
eventdate DATE
eventdesc varchar(255)
eventtype INT (FK)

Event type
----------------
eventtype INT (PK)
typedesc varchar(50)

Use event type table to crete a dropdown menu.

Create CSS styles for types of event so they display as different colors in the calendar (birthdays, anniversaries etc)
Link to comment
Share on other sites

this is my code now how do i make it so when i enter information into my sqldatabase it will underline the day number and make it a link?

[code]
// How many days are in the current month
$Days_In_Month = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));

// Gets the Current day, day with 1st 2nd etc, day name, year (2004), month,
// month name
$Current_Day = date("d");
$Current_Day_S = date("dS");
$Current_Day_Name = date("l");
$Current_Year = date("Y");
$Current_Month = date("m");
$Current_Month_Name = date("F");

// Get the offset of the first day of the month
$First_Day_Of_Month = date("w", mktime(0, 0, 0, $Current_Month, 1, $Current_Year));

// Set the day names
$Days_Array = array();
$Days_Array[] = "Sunday";
$Days_Array[] = "Monday";
$Days_Array[] = "Tuesday";
$Days_Array[] = "Wednesday";
$Days_Array[] = "Thursday";
$Days_Array[] = "Friday";
$Days_Array[] = "Saturday";

// For each of the Day Names, print em out
$Day_Names = "";
foreach ($Days_Array as $x => $y) {
    $Day_Names .= '<td align="center" bgcolor="#ADADAD" width="14.28%">' . $y . '</td>';
}

// Spacers for the offset of the first day of the month
$Cal_Weeks_Days = "";
$i = $First_Day_Of_Month + 1;
if ($First_Day_Of_Month != "0") {
    $Cal_Weeks_Days .= '<td colspan="' . $First_Day_Of_Month . '"> </td>';
}

// Cal Days - The first day is 1, default with PHP is 0, so lets set it to 1
$Day_i = "1";
$ii = $i;
for ($i; $i <= ($Days_In_Month + $First_Day_Of_Month);$i++) {
    // $i is our color variable - Alternate row colors:
    if ($i % 2) {
        $color = '#0000FF';
    }
    else
    {
        $color = '#0000FF';
    }

    // If the current day is sunday, make sure a new row gets set
    if ($ii == 8) {
        $Cal_Weeks_Days .= "</tr><tr>";
        $ii = 1;
    }

    // If the day is the current day, highlight it with a special color
    if ($Current_Day == $Day_i) {
        $Extra = 'bgcolor="#FF0000"';
    }
    else
    {
        // Alternate row colors
        $Extra = 'bgcolor="#' . $color . '"';
    }

    // Show the days.
    $Cal_Weeks_Days .= '<td height="65" valign="top" ' . $Extra . '>' . $Day_i . '</td>';

    // Increment the day number and the week day number (ii)
    $Day_i++;
    $ii++;
}

// Add end month spacers
if ((8 - $ii) >= "1") {
    $Cal_Weeks_Days .= '<td colspan="' . (8 - $ii) . '"> </td>';
}

// Echo the HTML
echo '<HTML>
<style type="text/css">
table,tr,td,th,tbody,TR,TD{
    font-family: Verdana;
    font-size: 8pt;
    font-size: 11; color: #000000;
    border-font-size: 11; color: #000000;
    border-collapse: collapse;
}
</style>';
echo '<table border="1" cellpadding="1" cellspacing="1" width="98%">
    <tr>
        <td align="center" colspan="7" bgcolor="#999999">'.$Current_Day_Name.' the '.$Current_Day_S.' of '.$Current_Month_Name.', '.$Current_Year.'</td>
    </tr>
    <tr>
        '.$Day_Names.'
    </tr>
    <tr>
        '.$Cal_Weeks_Days.'
    </tr>
</table>


</HTML>';
[/code]
Link to comment
Share on other sites

I added a couple of sections of code hilighted between //******************** lines

[code]
// How many days are in the current month
$Days_In_Month = cal_days_in_month(CAL_GREGORIAN, date("m"), date("Y"));

// Gets the Current day, day with 1st 2nd etc, day name, year (2004), month,
// month name
$Current_Day = date("d");
$Current_Day_S = date("dS");
$Current_Day_Name = date("l");
$Current_Year = date("Y");
$Current_Month = date("m");
$Current_Month_Name = date("F");

//************************************************************************
// get events for current month and store in array, keyed by day number
$sql = "SELECT eventdate FROM events WHERE YEAR(eventdate)=$Current_Year
        AND MONTH(eventdate)=$Current_Month";
$res = mysql_query($sql) or die (mysql_error());
$month_events = array();
while ($row = mysql_fetch_row($res)) {
       $month_events[date('j', strtotime($row[0]))] = $row[0]; # store date for link
}
//************************************************************************

// Get the offset of the first day of the month
$First_Day_Of_Month = date("w", mktime(0, 0, 0, $Current_Month, 1, $Current_Year));

// Set the day names
$Days_Array = array();
$Days_Array[] = "Sunday";
$Days_Array[] = "Monday";
$Days_Array[] = "Tuesday";
$Days_Array[] = "Wednesday";
$Days_Array[] = "Thursday";
$Days_Array[] = "Friday";
$Days_Array[] = "Saturday";

// For each of the Day Names, print em out
$Day_Names = "";
foreach ($Days_Array as $x => $y) {
    $Day_Names .= '<td align="center" bgcolor="#ADADAD" width="14.28%">' . $y . '</td>';
}

// Spacers for the offset of the first day of the month
$Cal_Weeks_Days = "";
$i = $First_Day_Of_Month + 1;
if ($First_Day_Of_Month != "0") {
    $Cal_Weeks_Days .= '<td colspan="' . $First_Day_Of_Month . '"> </td>';
}

// Cal Days - The first day is 1, default with PHP is 0, so lets set it to 1
$Day_i = "1";
$ii = $i;
for ($i; $i <= ($Days_In_Month + $First_Day_Of_Month);$i++) {
    // $i is our color variable - Alternate row colors:
    if ($i % 2) {
        $color = '#0000FF';
    }
    else
    {
        $color = '#0000FF';
    }

    // If the current day is sunday, make sure a new row gets set
    if ($ii == 8) {
        $Cal_Weeks_Days .= "</tr><tr>";
        $ii = 1;
    }

    // If the day is the current day, highlight it with a special color
    if ($Current_Day == $Day_i) {
        $Extra = 'bgcolor="#FF0000"';
    }
    else
    {
        // Alternate row colors
        $Extra = 'bgcolor="#' . $color . '"';
    }

    // Show the days.
    //*************************************************************************
    if (isset($month_events[$Day_i])) {   # have we an event
        $Day_i = "<a href='showEvents.php?d={$month_events[$Day_i]}'>$Day_i</a>"
    }

    //*************************************************************************
    $Cal_Weeks_Days .= '<td height="65" valign="top" ' . $Extra . '>' . $Day_i . '</td>';

    // Increment the day number and the week day number (ii)
    $Day_i++;
    $ii++;
}

// Add end month spacers
if ((8 - $ii) >= "1") {
    $Cal_Weeks_Days .= '<td colspan="' . (8 - $ii) . '"> </td>';
}

// Echo the HTML
echo '<HTML>
<style type="text/css">
table,tr,td,th,tbody,TR,TD{
    font-family: Verdana;
    font-size: 8pt;
    font-size: 11; color: #000000;
    border-font-size: 11; color: #000000;
    border-collapse: collapse;
}
</style>';
echo '<table border="1" cellpadding="1" cellspacing="1" width="98%">
    <tr>
        <td align="center" colspan="7" bgcolor="#999999">'.$Current_Day_Name.' the '.$Current_Day_S.' of '.$Current_Month_Name.', '.$Current_Year.'</td>
    </tr>
    <tr>
        '.$Day_Names.'
    </tr>
    <tr>
        '.$Cal_Weeks_Days.'
    </tr>
</table>


</HTML>';[/code]
Link to comment
Share on other sites

somethign happened to my script now whne i eneter an event into the database it causes the whol calendar dates to be the one i made an event for if thats making sense okay lets say i made one for 2006/04/06 as my bday ok, i would make everynumber on the calendar after the 6th the number 6 how could i fix that?
Link to comment
Share on other sites

Sorry, shouldn't have altered the value of $Day_i.

Change

[code]    //*************************************************************************
    if (isset($month_events[$Day_i])) {   # have we an event
        $Day_i = "<a href='showEvents.php?d={$month_events[$Day_i]}'>$Day_i</a>"
    }

    //*************************************************************************[/code]

to

[code]    //*************************************************************************
    if (isset($month_events[$Day_i])) {   # have we an event
        $DayLink = "<a href='showEvents.php?d={$month_events[$Day_i]}'>$Day_i</a>"
    }
    else $DayLink = $Day_i;

    //*************************************************************************[/code]

and in the following line, change "$Day_i " to "$DayLink"

[code]$Cal_Weeks_Days .= '<td height="65" valign="top" ' . $Extra . '>' . $DayLink. '</td>';[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.