nasıl ben ayın toplam gün yukarıdaki tüm numaralar yeni ay gün sayıları olarak görünmesini sağlayabilirsiniz?

3 Cevap php

I have a php calendar at http://idea-palette.com/aleventcal/calendar.php. I want the days that are not part of the current month to show up grayed out(which it does now), and I want it to appear as those are the days of the previous and next month.

Şimdi olduğu gibi, ayın ilk gününden önce görünür gün gibi olumsuz numaraları görünür (-1, -2, -3, ve benzeri) ve ayın son gününden sonra görünen gün hemen devam bir ay 31 biter eğer öyleyse, o zaman bu kadar üzerinde 32, 33, 34 okumak, ve olacaktır.

Ben başka bir şey yapmak daha sonra toplam gün daha büyükse ve ben görebiliyordu döngü çeşit koşullu bir ifadeyi anlamaya çalışıyorum. Gördüğüm sorun yaratılıyor tablo hücre döngüye ediliyor, bu yüzden ben sadece $ günde 1 yaparsanız yerine 32, daha sonra, sadece 33 okuyacaktır.

İşte benim kod:

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
        }
    }
}

3 Cevap

Sadece günün cari ayın gün sayısını çıkarın olumlu:

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
    }
}

İşte Geçenlerde yazdığım bir takvim işlevinin bir parçası, umarım ondan bazı fikirler alabilirsiniz.

// $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('Y-m-d') == date('Y-m-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);

Steve koşullu gerekmez: kullanmak yerine

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

Benim ne istediğinizi tam olan bir sonraki veya bir önceki aya taşıyarak Tarihleri ​​out-of-aralık mktime işler.