# How do I mark dates php modern-class-calendar script

**URL:** <https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037>\
**Category:** General PHP Help\
**Created:** [May 19, 2019, 10:08am UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037 "2019-05-19T10:08:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhelo](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rhelo](https://www.phphelp.com/u/rhelo)\
**Post date:** [May 19, 2019, 10:08am UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037/1 "2019-05-19T10:08:43Z")

</div>

Hello, I found this great free php calandar script here “[https://github.com/alecos71/modern-class-calendar](https://github.com/alecos71/modern-class-calendar)” by Xu and Alessandro, and I’m trying to modify the code to mark several dates(birthdays YYYY-mm-dd) from a date column in a sql database.

I’ve played around with the \_showDay() method but I can’t seem to get it working… I’ve also tried to create a \_showBirthday() method to modify the css as well but with no luck. What I’m trying to do is loop through the database to mark the respective dates on the calendar, and have a href to display a new page with the person’s name when I click the specific date.

Can anyone help with this. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![chorn](https://www.phphelp.com/letter_avatar_proxy/v4/letter/c/b5ac83/32.png) [@chorn](https://www.phphelp.com/u/chorn)\
**Post date:** [May 19, 2019, 11:59am UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037/2 "2019-05-19T11:59:10Z")

</div>

So what exactly did you try? Don’t make people replay your work, post a minimal example with mockdata.

---

<div class="post-metadata">

**Author:** ![rhelo](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rhelo](https://www.phphelp.com/u/rhelo)\
**Post date:** [May 19, 2019, 12:35pm UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037/3 "2019-05-19T12:35:32Z")

</div>

Hi chorn.. thanks for your response. I’m trying to use a loop to mark the first 5 days using $k). I modified the public function show() like this:  
(I added " for ($k = 1; $k \<= 5; $k++) { $content .= $this-\>\_showBirthdays($i \* 7 + $j, $k); } ")

and also created the \_showBirthdays() like this:  
(" private function \_showBirthdays($cellNumber, $k)  
{  
if ($this-\>currentDay == 0) {  
$firstDayOfTheWeek = date(‘N’, strtotime($this-\>currentYear . ‘-’ . $this-\>currentMonth . ‘-01’));  
if (intval($cellNumber) == intval($firstDayOfTheWeek)) {  
$this-\>currentDay = 1;  
}  
}  
if (($this-\>currentDay != 0) && ($this-\>currentDay \<= $this-\>daysInMonth)) {  
$this-\>currentDate = date(‘Y-m-d’, strtotime($this-\>currentYear . ‘-’ . $this-\>currentMonth . ‘-’ . ($this-\>currentDay)));  
$cellContent = $this-\>currentDay;  
$this-\>currentDay++;  
} else {  
$this-\>currentDate = null;  
$cellContent = null;  
}  
$today\_day = $k;//date(“d”);  
$today\_mon = date(“m”);  
$today\_yea = date(“Y”);  
$class\_day = ($cellContent == $today\_day && $this-\>currentMonth == $today\_mon && $this-\>currentYear == $today\_yea ? “calendar\_today” : “calendar\_days”);  
return ‘

’ . $cellContent . ‘
’ . “\r\n”;  
}")

but the new loop I created seems to do everything 5 times (especially print the entire

 ![Untitled](https://www.phphelp.com/uploads/default/original/2X/f/fa849102ac832ce70003e961740f4f3bf2fdcfd8.png) calendar 5x)

My Code:  
public function show()  
{  
$year = null;  
$month = null;  
if (null == $year && isset($\_GET[‘year’])) {  
$year = htmlentities($\_GET[‘year’], ENT\_QUOTES);  
} elseif (null == $year) {  
$year = date(“Y”, time());  
}  
if ((!is\_numeric($year)) || ($year == “”)) {  
$year = date(“Y”, time());  
}  
if (null == $month && isset($\_GET[‘month’])) {  
$month = htmlentities($\_GET[‘month’], ENT\_QUOTES);  
} elseif (null == $month) {  
$month = date(“m”, time());  
}  
if ((!is\_numeric($month)) || ($month == “”)) {  
$month = date(“m”, time());  
}  
$this-\>currentYear = $year;  
$this-\>currentMonth = $month;  
$this-\>daysInMonth = $this-\>\_daysInMonth($month, $year);  
$content = ‘

’ . “\r\n” . ‘
’ . “\r\n” . $this-\>\_createNavi() . “\r\n” . ‘
’ . “\r\n” . ‘
’ . “\r\n” . ‘
’ . “\r\n” . $this-\>\_createLabels() . ‘
’ . “\r\n”;  
$content .= ‘

’ . “\r\n”;  
$content .= ‘
’ . “\r\n”;  
$weeksInMonth = $this-\>\_weeksInMonth($month, $year);  
// Create weeks in a month  
for ($i = 0; $i \< $weeksInMonth; $i++) {  
// Create days in a week  
for ($j = 1; $j \<= 7; $j++) {  
//$content .= $this-\>\_showDay($i \* 7 + $j);

```
            for ($k = 1; $k <= 5; $k++) {
                $content .= $this->_showBirthdays($i * 7 + $j, $k);
            }
        }
    }
    $content .= '</div>' . "\r\n";
    $content .= '<div class="calendar_clear"></div>' . "\r\n";
    $content .= '</div>' . "\r\n";
    $content .= '</div>' . "\r\n";
    return $content;
}

```

---

<div class="post-metadata">

**Author:** ![rhelo](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rhelo](https://www.phphelp.com/u/rhelo)\
**Post date:** [May 19, 2019, 12:50pm UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037/4 "2019-05-19T12:50:14Z")

</div>

If I’m able to sucessfully mark the first 5days, then I can mark any number of dates from a database. Thanks again!

---

<div class="post-metadata">

**Author:** ![johnphpnewb](https://www.phphelp.com/user_avatar/www.phphelp.com/johnphpnewb/32/2219_2.png) [@johnphpnewb](https://www.phphelp.com/u/johnphpnewb)\
**Post date:** [May 21, 2019, 10:22am UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037/5 "2019-05-21T10:22:32Z")

</div>

> [@rhelo](#):
>
> for ($k = 1; $k \<= 5; $k++) { $content .= $this-\>\_showBirthdays($i \* 7 + $j, $k); } } } $content .= ‘\</div\>’ . “\r\n”; $content .= ‘\<div class=“calendar\_clear”\>\</div\>’ . “\r\n”; $content .= ‘\</div\>’ . “\r\n”; $content .= ‘\</div\>’ . “\r\n”; return $content; }

but you are looping five times and concatenating the strings. without delving into your code, it appears to me that you have designed this outcome. So if this is not what you want, then try to redesign the loop. I may not see this correctly, so correct me if i’m wrong, but i think that .= continues to append to the content and five times. .= does not erase the string and start over.

---

<div class="post-metadata">

**Author:** ![rhelo](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/bbe5ce/32.png) [@rhelo](https://www.phphelp.com/u/rhelo)\
**Post date:** [May 21, 2019, 10:50am UTC](https://www.phphelp.com/t/how-do-i-mark-dates-php-modern-class-calendar-script/29037/6 "2019-05-21T10:50:32Z")

</div>

@johnphpnewb Thanks for your response. I had it working like so (I simply created a new date array with the dates I intend to highlight, and then checked for equality in the \_showDay method). No more need for any loop

```
    if (in_array($this->currentDate, $this->highlight_dates)) {
        $class_day = "calendar_birthday"; // uses the existing 'today' css. change as needed
        $cellContent = $this->currentDay;
    }
```
