Jump to content

Calendar - How do I do this????


boney alex

Recommended Posts

Ive found a simple calendar that displays all the days of the month as a link. I have saved the code below as eventcalendar.php and what I would like is when the user selects a certain day, that will take them to a page saved as eventinfo.php with the events for that day. I have managed to point each link to eventinfo.php, I'm just struggling to pass the actual date to that page, any ideas??

 

<?php mk_drawCalendar($_GET['m'],$_GET['y']); ?>

</blockquote>
</body>
</html>


<?php

//*********************************************************
// DRAW CALENDAR
//*********************************************************

function mk_drawCalendar($m,$y)
{
    if ((!$m) || (!$y))
    { 
        $m = date("m",mktime());
        $y = date("Y",mktime());
    }

    /*== get what weekday the first is on ==*/
    $tmpd = getdate(mktime(0,0,0,$m,1,$y));
    $month = $tmpd["month"]; 
    $firstwday= $tmpd["wday"];

    $lastday = mk_getLastDayofMonth($m,$y);

?>
<table cellpadding="2" cellspacing="0" border="1">
<tr><td colspan="7" bgcolor="#CCCCDD">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr><th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th>
    <th><font size=2><?="$month $y"?></font></th>
    <th width="20"><a href="<?php echo $_SERVER['PHP_SELF']; ?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th>
    </tr></table>
</td></tr>

<tr><th width=22 class="tcell">Su</th><th width=22 class="tcell">M</th>
    <th width=22 class="tcell">T </th><th width=22 class="tcell">W</th>
    <th width=22 class="tcell">Th</th><th width=22 class="tcell">F</th>
    <th width=22 class="tcell">Sa</th></tr>

<?php $d = 1;
    $wday = $firstwday;
    $firstweek = true;

    /*== loop through all the days of the month ==*/
    while ( $d <= $lastday) 
    {

        /*== set up blank days for first week ==*/
        if ($firstweek) {
            echo "<tr>";
            for ($i=1; $i<=$firstwday; $i++) 
            { echo "<td><font size=2> </font></td>"; }
            $firstweek = false;
        }

        /*== Sunday start week with <tr> ==*/
        if ($wday==0) { echo "<tr>"; }

        /*== check for event ==*/  
        echo "<td class='tcell'>";
        echo "<a href=\"eventinfo.php\" onClick=\"eventdate.value='$d-$m-$y';\">$d</a>";
        echo "</td>\n";

        /*== Saturday end week with </tr> ==*/
        if ($wday==6) { echo "</tr>\n"; }

        $wday++;
        $wday = $wday % 7;
        $d++;
    }
?>

</tr></table>
Click on a date to select it and to populate the event date field on the left
<br />

<?php
/*== end drawCalendar function ==*/
} 

/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
    for ($tday=28; $tday <= 31; $tday++) 
    {
        $tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
        if ($tdate["mon"] != $mon) 
        { break; }

    }
    $tday--;

    return $tday;
}

?>

 

I think that the problem lies somewhere around this line:

        echo "<a href=\"eventinfo.php\" onClick=\"eventdate.value='$d-$m-$y';\">$d</a>";

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/47783-calendar-how-do-i-do-this/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.