Alright.  I was recently writting an attendance application for a school.  I
wanted to beable to display attendance information from mysql in a calendar,
but I did not want to have to write the calendar script from scratch.  I
must have looked at thirty or so calendar scripts before I found this one:
http://www.stevenrebello.f2s.com/ .  I chose this calendar because it looks
nice, but is very simple and does not contain a bunch of stuff I don't need.

I rewrote the script as a function and changed it to fit my needs.  I will
include the source here so that you can see how I made it work with mysql.
There are two places where I made changes.  First, you can see that I
changed the code for generating the links to last month and next month.  You
will need to do this in order to pass the correct variables to the page that
contains the function.

I then added the code for priting my dadabase information.  Most of the code
for formatting the data for each day is in a seperate function that gets
called once for each day on the calendar.  You will notice that I have the
database code in there twice.  This is because I did things a little
differently for the current day.  This is not necessary, but you will have
to rearrange the code a bit if you still want to highlight the current day.

Good Luck.
function  AttendanceCalendar($mon,$year,$Student,$Class)
{
  global $dates, $first_day, $start_day, $Attend;

  $first_day = mktime(0,0,0,$mon,1,$year);
  $start_day = date("w",$first_day);
  $res = getdate($first_day);
  $month_name = $res["month"];
  $no_days_in_month = date("t",$first_day);

  file://If month's first day does not start with first Sunday, fill table
cell with a space
  for ($i = 1; $i <= $start_day;$i++)
   $dates[1][$i] = " ";

  $row = 1;
  $col = $start_day+1;
  $num = 1;
  while($num<=31)
   {
    if ($num > $no_days_in_month)
      break;
    else
     {
      $dates[$row][$col] = $num;
      if (($col + 1) > 7)
       {
        $row++;
        $col = 1;
       }
      else
       $col++;
      $num++;
     }//if-else
   }//while
  $mon_num = date("n",$first_day);
  $temp_yr = $next_yr = $prev_yr = $year;

  $prev = $mon_num - 1;
  $next = $mon_num + 1;

  file://If January is currently displayed, month previous is December of
previous year
  if ($mon_num == 1)
   {
    $prev_yr = $year - 1;
    $prev = 12;
   }

  file://If December is currently displayed, month next is January of next
year
  if ($mon_num == 12)
   {
    $next_yr = $year + 1;
    $next = 1;
   }

  echo "<TABLE BORDER=\"1\" WIDTH=\"100%\" CELLSPACING=\"0\"
BORDERCOLOR=\"cc3333\">";

  echo  "\n<TR ALIGN='center'><TD BGCOLOR='white'> ".
    "<A
HREF=\"$PHP_SELF?Module=Student&Student=$Student&Class=$Class&month=$prev&ye
ar=$prev_yr\" STYLE=\"text-decoration: none\"><B><<</B></A> </TD>".
    "<TD COLSPAN=5 BGCOLOR='cc3333'><B><FONT
Color='ffffff'>".date("F",$first_day)." ".$temp_yr."</B></FONT></TD>".
    "<TD BGCOLOR='white'> ".
    "<A
HREF=\"$PHP_SELF?Module=Student&Student=$Student&Class=$Class&month=$next&ye
ar=$next_yr\" STYLE=\"text-decoration: none\"><B>>></B></A> </TD></TR>";

  echo "\n<TR
ALIGN='center'><TD><B>Sun</B></TD><TD><B>Mon</B></TD><TD><B>Tue</B></TD>";
  echo
"<TD><B>Wed</B></TD><TD><B>Thu</B></TD><TD><B>Fri</B></TD><TD><B>Sat</B></TD
></TR>";
  echo "<TR><TD COLSPAN=7> </TR><TR ALIGN='center'>";

  $end = ($start_day > 4)? 6:5;
  for ($row=1;$row<=$end;$row++)
   {
    for ($col=1;$col<=7;$col++)
     {
      if ($dates[$row][$col] == "")
      $dates[$row][$col] = " ";

      if (!strcmp($dates[$row][$col]," "))
       $count++;

      $t = $dates[$row][$col];

      file://If date is today, highlight it
      if (($t == date("j")) && ($mon == date("n")) && ($year == date("Y")))
      {
       file://echo "\n<TD BGCOLOR='cccccc'>".$t."</TD>";
       echo "\n<TD bgcolor=\"cccccc\">";//.(($t == " " )? "&nbsp;"
:$t)."</TD>";

       $Result = mysql_query("SELECT Attend, Credit, Date FROM Attendance
WHERE StudentID = \"$Student\" AND SectionNo = \"$Class\" AND MONTH(Date) =
\"$mon\" AND YEAR(Date) = \"$year\" AND DAYOFMONTH(Date) = \"$t\"",
MakeConn())
               or die (mysql_error());

       if (mysql_num_rows($Result) > 0)
       {
       $DataRow = mysql_fetch_assoc($Result);
       extract ($DataRow);
       PrintDay($Attend,$Credit,$t,$mon,$year);
       mysql_free_result($Result);
       }

       echo "</TD>";}
      else {
      if ($t == " ") {
      echo "\n<TD>";
      echo "</TD>";
      }else{
       file://If the date is absent ie after 31, print space
       echo "\n<TD width=\"60\" height=\"60\">";//.(($t == " " )? "&nbsp;"
:$t)."</TD>";

       $Result = mysql_query("SELECT Attend, Credit, Date FROM Attendance
WHERE StudentID = \"$Student\" AND SectionNo = \"$Class\" AND MONTH(Date) =
\"$mon\" AND YEAR(Date) = \"$year\" AND DAYOFMONTH(Date) = \"$t\"",
MakeConn())
               or die (mysql_error());

       if (mysql_num_rows($Result) > 0)
       {
       $DataRow = mysql_fetch_assoc($Result);
       extract ($DataRow);
       PrintDay($Attend,$Credit,$t,$mon,$year);
       mysql_free_result($Result);
       }
       else
       {
       echo $t;
       }



       echo "</TD>";}}
     }// for -col

    if (($row + 1) != ($end+1))
     echo "</TR>\n<TR ALIGN='center'>";
    else
     echo "</TR>";
   }// for - row
  echo "\n</TABLE>";
}




Sjoerd Van Oosten <[EMAIL PROTECTED]> wrote in message
C9F89DA57491D511BDAF00E0180C348103BFED@ESADM01">news:C9F89DA57491D511BDAF00E0180C348103BFED@ESADM01...
> Of course i'm very interested!
>
> Greetings,
>
> ________________________________________
> Sjoerd van Oosten
> Digitaal vormgever [EMAIL PROTECTED]
> Datamex E-sites B.V.
> http://www.esites.nl
> Minervum 7368 Telefoon: (076) 5 730 730
> 4817 ZH BREDA Telefax: (076) 5 877 757
> _______________________________________
>
>
> -----Oorspronkelijk bericht-----
> Van: Fred [mailto:[EMAIL PROTECTED]]
> Verzonden: dinsdag 20 november 2001 9:35
> Aan: [EMAIL PROTECTED]
> Onderwerp: [PHP] Re: DATE Questions
>
>
> If you are interested I can show you a script that will generate a monthly
> calendar based on the current date.  It has links to go forward and
backward
> by month.  It is a fairly simple script that I found at hotscripts.com,
but
> it has amazing potential.  I have used it as the basis for some rather
> advanced database applications.
>
> Fred
>
>
> Sjoerd Van Oosten <[EMAIL PROTECTED]> wrote in message
> C9F89DA57491D511BDAF00E0180C348103BFE5@ESADM01">news:C9F89DA57491D511BDAF00E0180C348103BFE5@ESADM01...
> >
> > Hello,
> >
> > I'm working on a project planning system and what i want to do is making
a
> > sort of table structure with an overview form today till a month later.
> All
> > the projects that are between these dates must be viewed.
> >
> > Right now i have the following questions:
> >
> > - How can i determine how much days are between say 20 november and 20
> > december dynamically?
> > - How can i make an array containing the values of these dates?
> > - How do i make a for loop and print these values.
> >
> > I hope somone can help me out. Thanks.
> > ________________________________________
> > Sjoerd van Oosten
> > Digitaal vormgever [EMAIL PROTECTED]
> > Datamex E-sites B.V.
> > http://www.esites.nl
> > Minervum 7368 Telefoon: (076) 5 730 730
> > 4817 ZH BREDA Telefax: (076) 5 877 757
> > _______________________________________
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to