как я могу сделать какие-то цифры выше общих дней месяца, как новые числа дневного месяца?

У меня есть php-календарь на http://idea-palette.com/aleventcal/calendar.php . Я хочу, чтобы дни, которые не являются частью текущего месяца, отображались серым цветом (что сейчас происходит), и я хочу, чтобы они отображались, так как это дни предыдущего и следующего месяца.

Как и сейчас, дни, которые появляются до первого дня месяца, отображаются как отрицательные числа (-1, -2, -3 и т. Д.), И дни, которые появляются после последнего дня месяца, просто продолжаются, поэтому, если месяц заканчивается на 31-м, тогда он будет читать 32, 33, 34 и т. д.

Я пытаюсь выяснить условное утверждение с каким-то циклом, где я мог видеть, если он больше, чем общие дни, а затем сделать что-то еще. Проблема, которую я вижу, в том, что создаваемая ячейка таблицы зацикливается, поэтому, если я делаю всего $ day + 1, то вместо 32 она будет читать 33.

Вот мой код:

for($i=0; $i< $total_rows; $i++) { for($j=0; $j<7;$j++) { $day++; //if the current day is less or equal to the total days in the month if($day>0 && $day<=$total_days_of_current_month) { $date_form = "$current_year/$current_month/$day"; echo '<div class="date_has_event" href="#"><td'; //If the date is today then give the td cell the 'today' class if($date_form == $today) { echo ' class="today"'; } //check if any event stored for the date if(array_key_exists($day,$events)) { //adding the date_has_event class to the <td> and close it echo ' class="date_has_event">'.$day; //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul> echo '<div class="events"><ul>'.$events[$day].'</ul></div>'; } } else //if the current day is less or more than the total days in the month { //then create a table cell with the current day of the mont echo '<td class="padding">' . $day . '&nbsp;</td>'; h } } } 

просто вычесть количество дней в текущем месяце дня положительно:

 else //if the current day is less or more than the total days in the month { if($day > 1){ echo '<td class="padding">' . ($day - $total_days_of_current_month) . ' </td>'; // the next month } else { echo '<td class="padding">' . $day . ' </td>'; //then create a table cell with the current day of the month } } 

Вот часть функции календаря, которую я недавно написал, вы можете надеяться получить от нее некоторые идеи.

 // $month is a UNIX timestamp // resetting to 1st of the month $date = getdate(mktime(0, 0, 0, date('n', $month), 1, date('Y', $month))); // resetting to first day in grid $date = getdate(strtotime("-$date[wday] days", $date[0])); $out = array(); $lastDay = mktime(0, 0, 0, date('n', $month), date('t', $month), date('Y', $month)); while ($date[0] <= $lastDay) { $row = array(); for ($x = 0; $x <= 6; $x++) { $attr = array('class' => 'weekday '.low(date('D', $date[0]))); if (date('n', $month) != $date['mon']) { $attr['class'].= ' prevNextMonth'; } if (date('Ym-d') == date('Ym-d', $date[0])) { $attr['class'].= ' today'; } $row[] = array($date['mday'], $attr); $date = getdate(strtotime("+1 day", $date[0])); } $out[] = $row; } // makes table rows out of the array, considers the $attr array as well $out = $this->Html->tableCells($out); $out = sprintf('<table><tbody>%s</tbody></table>', $out); 

Вы не нуждаетесь в условности Стиву: вместо этого используйте

echo '<td class="padding">' . date("j",mktime(12,0,0,$current_month,$day,$current_year)) . ' </td>';

mktime обрабатывает даты вне диапазона, меняя их в следующий или предыдущий месяц, и это именно то, что вы хотите.