ayok Posted February 8, 2008 Share Posted February 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/89987-calendar-help/ Share on other sites More sharing options...
JacobYaYa Posted February 8, 2008 Share Posted February 8, 2008 You can do [...] echo "<td style=\"background-color:#ff0000\">$day_link</td>\n"; [...] Better to do it with a class to keep the web standards mob happy. Quote Link to comment https://forums.phpfreaks.com/topic/89987-calendar-help/#findComment-461376 Share on other sites More sharing options...
ayok Posted February 8, 2008 Author Share Posted February 8, 2008 Thanks for your reply, Jacob. But it still doesn't work. I think The if statement I made is wrong. Anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/89987-calendar-help/#findComment-461591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.