Jump to content

Calendar Help


ayok

Recommended Posts

Hi,

 

I found a calendar script from a tutorial in this site. I combined it with mysql query so that I can put events into the database. So if i click on a date where there is an event, the title and description of the event will occur.

 

The problem is, I need to mark the date which has event in it. I tried to add color to the date's column, but it didn't work.

 

Here is a part of the code where the dates are shown:

<?php
    if (!isset($_REQUEST['date']))
    {
        $date = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
    }
    else
    {
        $date = $_REQUEST['date'];
    }

    $day = date('d', $date);
    $month = date('m', $date);
    $year = date('Y', $date);
    $today = date("D", $date);

    // Get the first day of the month
    $month_start = mktime(0, 0, 0, $month, 1, $year);

    // Get friendly month name
    $month_name = date('M', $month_start);
    $month_start_day = date('D', $month_start);

    switch ($month_start_day)
    {
        case "Sun":
            $offset = 0;
            break;
        case "Mon":
            $offset = 1;
            break;
        case "Tue":
            $offset = 2;
            break;
        case "Wed":
            $offset = 3;
            break;
        case "Thu":
            $offset = 4;
            break;
        case "Fri":
            $offset = 5;
            break;
        case "Sat":
            $offset = 6;
            break;
    }
    if ($month == 1)
    {
        $num_days_last = cal_days_in_month(0, 12, ($year - 1));
    }
    else
    {
        $num_days_last = cal_days_in_month(0, ($month - 1), $year);
    }
    $num_days_current = cal_days_in_month(0, $month, $year);

    for ($i = 1; $i <= $num_days_current; $i++)
    {
        $num_days_array[] = $i;
    }
    for ($i = 1; $i <= $num_days_last; $i++)
    {
        $num_days_last_array[] = $i;
    }
    if ($offset > 0)
    {
        $offset_correction = array_slice($num_days_last_array, -$offset, $offset);
        $new_count = array_merge($offset_correction, $num_days_array);
        $offset_count = count($offset_correction);
    }
    else
    {
        $offset_count = 0;
        $new_count = $num_days_array;
    }
    $current_num = count($new_count);
    if ($current_num > 35)
    {
        $num_weeks = 6;
        $outset = (42 - $current_num);
    }
    elseif ($current_num < 35)
    {
        $num_weeks = 5;
        $outset = (35 - $current_num);
    }
    if ($current_num == 35)
    {
        $num_weeks = 5;
        $outset = 0;
    }

for ($i = 1; $i <= $outset; $i++)
    {
        $new_count[] = $i;
    }
$weeks = array_chunk($new_count, 7);
     include '../../connection/db.php';
    $thevents = mysql_query("select * from calendar where date_event='$date'") or die(mysql_error());
    $data = mysql_fetch_array($thevents);
    $i = 0;
foreach ($weeks as $week)
    {
        echo "<tr>\n";
        foreach ($week as $d)
        {
            if ($i < $offset_count)
            {
                $day_link = "<a href=\"" . $_SERVER['PHP_SELF'] . "?date=" . mktime(0, 0, 0, $month -
                    1, $d, $year) . "\">$d</a>";
                echo "<td bgcolor=#FFCCFF>$day_link</td>\n";
            }
            if (($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset))
            {
                $day_link = "<a href=\"" . $_SERVER['PHP_SELF'] . "?date=" . mktime(0, 0, 0, $month,
                    $d, $year) . "\">$d</a>";
                if ($date == mktime(0, 0, 0, $month, $d, $year))
                {
                    echo "<td bgcolor=#FFFFFF>$d</td>\n";
                }
                else
                {
                    echo "<td>$day_link</td>\n";
                }
            }
            elseif (($outset > 0))
            {
                if (($i >= ($num_weeks * 7) - $outset))
                {
                    $day_link = "<a href=\"" . $_SERVER['PHP_SELF'] . "?date=" . mktime(0, 0, 0, $month +
                        1, $d, $year) . "\">$d</a>";
                    echo "<td bgcolor=#FFCCFF>$day_link</td>\n";
                }
            }
            $i++;
        }
        echo "</tr>\n";
    }

 

What is the proper if statement to mark the dates with event on it? I've tried to insert this if statement:

<?php if($date == $data['date_event']){
				echo "<td bgcolor=#ff0000>$day_link</td>\n";
			}

But it doesn't work.

Could someone please help me?

Thank you,

 

ayok

Link to comment
https://forums.phpfreaks.com/topic/89987-calendar-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.