AndrewJ1313 Posted March 21, 2008 Share Posted March 21, 2008 I've created a calendar using PHP which displays the current month. Below is my code: <?php function showMonth($month, $year) { $date = mktime(12, 0, 0, $month, 1, $year); $daysInMonth = date("t", $date); $offset = date("w", $date); $rows = 1; echo "<span class='sideLinksActive'><strong>" . date("F Y", $date) . "</strong></span>\n"; echo "<table border='0' cellpadding='0' cellspacing='0' bgcolor='white'>\n"; echo "\t<tr class='sideLinks' bgcolor='#003366' height='25'><td width='70' align='center'><strong>S</strong></td><td width='70' align='center'><strong>M</strong></td><td width='70' align='center'><strong>T</strong></td><td width='70' align='center'><strong>W</strong></td><td width='70' align='center'><strong>T</strong></td><td width='70' align='center'><strong>F</strong></td><td width='70' align='center'><strong>S</strong></td></tr>"; echo "\n\t<tr>"; for($i = 1; $i <= $offset; $i++) { echo "<td width='70' height='50' align='center' valign='middle' class='bodyText_Link'></td>"; } for($day = 1; $day <= $daysInMonth; $day++) { if( ($day + $offset - 1) % 7 == 0 && $day != 1) { echo "</tr>\n\t<tr>"; $rows++; } echo "<td height='50' align='center' valign='middle' class='bodyText_Link'>" . $day . "</td>"; } while( ($day + $offset) <= $rows * 7) { echo "<td height='50' align='center' valign='middle' class='bodyText_Link'></td>"; $day++; } echo "</tr>\n"; echo "</table>\n"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>Calendar</title> <link href="css_nazarene/johnstownnaz.css" rel="stylesheet" type="text/css" /> </head> <body> <table border="1" cellpadding="0" cellspacing="0" bordercolor="#333333" bgcolor="#FFFFFF"> <tr><td> <?php $todayIs = date("l, F j, Y"); $time = date("g:iA"); echo("<p class='bodyText'>Today is $todayIs, $time</p>"); $todayMonth = $_GET['month']; $todayYear = $_GET['year']; showMonth($todayMonth, $todayYear); ?> </td> </tr> </table> </body> </html> I would like to change the background color of the <td> which displays the current day. Does anyone have a suggestion for this? I tried looking under the PHP Tutorials section of this forum, but there were no postings under Calendar/Date Time. Thank you to all who reply. Andrew Link to comment https://forums.phpfreaks.com/topic/97258-php-calendar-help/ Share on other sites More sharing options...
Jeremysr Posted March 21, 2008 Share Posted March 21, 2008 If I understand your code right, this should work: if (date('j') == $day) { echo "<td height='50' align='center' valign='middle' class='bodyText_Link' style='background-color: #fff;'>" . $day . "</td>"; } else { echo "<td height='50' align='center' valign='middle' class='bodyText_Link'>" . $day . "</td>"; } Link to comment https://forums.phpfreaks.com/topic/97258-php-calendar-help/#findComment-497680 Share on other sites More sharing options...
AndrewJ1313 Posted March 21, 2008 Author Share Posted March 21, 2008 Works perfectly! I thought I was over thinking it so I figured someone here would know how to do it. Thanks, Andrew Link to comment https://forums.phpfreaks.com/topic/97258-php-calendar-help/#findComment-497686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.