Calendar. How to put empty cells in the row

Hi

I have a script for calendar, but I do not know how add empty cells in the beginning of the month if the first day of the month is not Monday
For example, 1st Jan 2016 is Friday, but calander shows it as Monday

[php]<?php $iteration = 0;
for($i=1;$i<13;$i++){ ?>

<?php $jd=gregoriantojd($i, 01, 2016); ?> <?php echo jdmonthname($jd, 0);?> <?php $number = cal_days_in_month(CAL_GREGORIAN, $i, 2016); for($d = 1; $d < $number; $d++){ $iteration++; $day_of_week = JDDayOfWeek(cal_to_jd(CAL_GREGORIAN, $i, $d, '2016'), 2); $first_day_of_month = JDDayOfWeek(cal_to_jd(CAL_GREGORIAN, $i, 01, '2016'), 2);
if($iteration == 1){ ?>
    <tr> 
      
<?php } ?> 
<td>
<?php echo $d; ?> <?php if($iteration % 7 == 0){ ?>
<?php } 
        } ?>
Mon Tue Wed Thu Fri Sat Sun
<?php } ?>[/php]

What did you try so far? Think out of the box… You need to keep a counter of some sort to mark the first day of the month.
Then, where you display your one day’s data like this:

<?php echo $d; ?> You would need to check if the
day is visible in the month or not. Then, display the $d, but, if not visible, do not display it.

One way might be to calculate the first day that is visible and then check if the day is equal to or greater than that day.
Thinking OUT of the box, you must remember that you can NOT just figure out the number of days in the month and then
start displaying them before or after Monday or Sunday. (Sunday starts off the week, normally) So, either you loop thru the
month and calculate the day of the month that the first day is. Since the first day of the current money can start anywhere
inside of the current week, you can not simply loop thru all the days in the week and know what month that day is in. Let’s
say the month starts on Wednesday, but you started displaying the week on Monday? How do you know it is LAST month
for those two days? You could calculate the day of that week that the month starts in and then not display it if before that
date.

You must rethink how you are looping thru the days. Does that make sense? So if you are displaying the first week of
the month and first day of the month is the 6th day of the first week on a Saturday, you need to also know what day the first
Monday is from the last month so you can skip that many days. (So that Friday ends up being the 31st or 30th from
the month before…) Tricky, but, you can figure it out. Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service