PHP calendar.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kitaeshi
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2009 12:13 am

PHP calendar.

Post by kitaeshi »

Hi i have problem with php date, i d/l a calendar.php from the webby & tried to integrate it into my coding but the calendar is showing D/MM/YYYY for single digit like day 1-9 & not 01-09 & mysql cannot accept D/MM/YYYY, it must be DD/MM/YYYY for it to accept.
Hope somebody can help amend the calendar to display correctly

Code: Select all

<html>
<head>
<title>PHP Event Calendar</title>
<script type="text/css">
body.margin{margin-top:0}
body{margin-left:0}
</script>
<body bgcolor="#FFFFFF" link="#0000CC" vlink="#0000CC">
 
<table>
<tr>
<td valign="top"><?php mk_drawCalendar($_GET['m'],$_GET['y']); ?></td>
<td width="25" nowrap><br /></td>
 
    <form name="f" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    <table cellpadding="0" cellspacing="0" border="0" bgcolor="#000000"><tr><td>
    </form>
 
</td>
</tr></table>
</blockquote>
</body>
</html>
 
 
<?php
 
//*********************************************************
// DRAW CALENDAR
//*********************************************************
/*
    Draws out a calendar (in html) of the month/year
    passed to it date passed in format mm-dd-yyyy
*/
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>&nbsp;</font></td>"; }
            $firstweek = false;
        }
 
        /*== Sunday start week with <tr> ==*/
        if ($wday==0) { echo "<tr>"; }
 
        /*== check for event ==*/
        echo "<td class='tcell'>";
        echo "<a href=\"appointmentCreate.php?eventdate=$d-$m-$y\" target=\"innerHtml\">$d</a>";
        echo "</td>\n";
 
 
        /*== Saturday end week with </tr> ==*/
        if ($wday==6) { echo "</tr>\n"; }
 
        $wday++;
        $wday = $wday % 7;
        $d++;
    }
?>
 
</tr></table>
 
<?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;
}
exit();
?>
 
Last edited by kitaeshi on Sat Jan 31, 2009 6:39 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP calendar.

Post by pickle »

Somewhere in there (the code should be in [ code=php ]  tags by the way, not just [ code=text ] ), the date() function is being used with the 'j' argument - changing that to 'd' might work.

http://ca.php.net/manual/en/function.date.php
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
kitaeshi
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2009 12:13 am

Re: PHP calendar.

Post by kitaeshi »

hi there, don't think there is any character "j" inside the code... the mth also displaying as D/M/YYYY.... i suspect it have to do with the looping as the first 9 digit is single digit..
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Re: PHP calendar.

Post by Citizen »

What pickle is saying is that editing your post and changing to... will help us read your code to find your problem.
kitaeshi
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2009 12:13 am

Re: PHP calendar.

Post by kitaeshi »

done tat. ^^
Post Reply