Question

Design Overview and Requirements As part of the first submission point, you should generate a static calendar for the current

PHP code for a calendar using  control structures

0 0
Add a comment Improve this question Transcribed image text
Answer #1

<!DOCTYPE html>
<html>
<style>
/* calendar */
h2 {background-color:#00FF7F !important;padding-top:10px !important;padding-bottom:10px !important}
/*.calendar       { border-left:1px solid #999; }*/
.calendarday   { min-height:80px; font-size:11px; position:relative; } * html div.calendarday { height:80px; }
.calendarday:hover   { background:#eceff5; }
.calendarEmpty   { background:#eee; min-height:80px; } * html div.calendarEmpty { height:80px; }
.calendarheading { background:#ccc; font-weight:bold; text-align:left; width:120px; padding:22px; border-bottom:1px solid #fff; border-top:1px solid #fff; border-right:1px solid #fff; }
.dayNumber       { padding:5px; color:#000; font-weight:bold; float:right; margin:-5px -5px 0 0; width:20px; text-align:center; }
/* shared */
.calendarday,.calendarEmpty {background-color:#eee;width:120px; padding:22px; border-bottom:1px solid #fff; border-right:1px solid #fff; }

</style>
<body>

<?php
/* draws a calendar of given month and year*/
function displayCalendar($month,$year){

   /* draw table */
   $calendar = '<table cellpadding="0" cellspacing="2" class="calendar">';

   /* table headings */
   $calendarheadings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
   $calendar.= '<tr class="calendar-row"><td class="calendarheading">'.implode('</td><td class="calendarheading">',$calendarheadings).'</td></tr>';

  
   $running_day = date('w',mktime(0,0,0,$month,1,$year));
   $days_in_month = date('t',mktime(0,0,0,$month,1,$year));
   $days_in_this_week = 1;
   $day_counter = 0;
   $dates_array = array();

   /* row for week one */
   $calendar.= '<tr class="calendar-row">';

   /* print "blank" days until the first of the current week */
   for($x = 0; $x < $running_day; $x++):
       $calendar.= '<td class="calendarEmpty"> </td>';
       $days_in_this_week++;
   endfor;

   /* keep going with days.... */
   for($list_day = 1; $list_day <= $days_in_month; $list_day++):
       $calendar.= '<td class="calendarday">';
           /* add in the day number */
           $calendar.= '<div class="dayNumber">'.$list_day.'</div>';

           /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/
           $calendar.= str_repeat('<p> </p>',2);
          
       $calendar.= '</td>';
       if($running_day == 6):
           $calendar.= '</tr>';
           if(($day_counter+1) != $days_in_month):
               $calendar.= '<tr class="calendar-row">';
           endif;
           $running_day = -1;
           $days_in_this_week = 0;
       endif;
       $days_in_this_week++; $running_day++; $day_counter++;
   endfor;

   /* finish the rest of the days in the week */
   if($days_in_this_week < 8):
       for($x = 1; $x <= (8 - $days_in_this_week); $x++):
           $calendar.= '<td class="calendarEmpty"> </td>';
       endfor;
   endif;

   /* final row */
   $calendar.= '</tr>';

   /* end the table */
   $calendar.= '</table>';
  
   /* all done, return result */
   return $calendar;
}

/*get the current month and Year and pass it to draw calendar function*/
$now = new \DateTime('now');
$month = $now->format('m');
$monthName = $now->format('F');
$year = $now->format('Y');
echo "<h2 align='center'>".$monthName." ".$year."</h2>";
echo displayCalendar($month,$year);
?>

</body>
</html>June 2019 Saturday Friday Thursday Wednesday Tuesday Monday Sunday 1 S 5 3 2 15 14 13 12 11 10 21 21 20 10 19 17 16

Add a comment
Know the answer?
Add Answer to:
PHP code for a calendar using  control structures Design Overview and Requirements As part of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT