zed420 Posted August 3, 2009 Share Posted August 3, 2009 Hi All I've taken this simple calendar from net I'm trying to highlight Today's date I can NOT seem to work it out. Some help will be greatly appreciated. Thanks Zed <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <div id="calendar_div" name="calendar_div"> <table width="400"> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td> </tr> <tr> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ) echo "<tr>\n"; if($i < $startday) echo "<td></td>\n"; else echo "<td align='center' valign='middle' height='20px'> <a href=\"test.php\" STYLE=\"TEXT-DECORATION: NONE\">". ($i - $startday + 1) . "</td>\n"; if(($i % 7) == 6 ) echo "</tr>\n"; } ?> </table> </td> </tr> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/ Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 I added the current day outside the for loop which is $today = date("j"); then I put ($i - $startday + 1) in a variable called $day inside the loop. If $day == $today then add the bold tags to the $day var, else dont. then print day Now instead of BOLD tags you can use something else, just change this line if($day == $today){ $day = "<b>".($i - $startday + 1)."</b>"; } else { $day = ($i - $startday + 1); } <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <div id="calendar_div" name="calendar_div"> <table width="400"> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td> </tr> <tr> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; $today = date("j"); for ($i=0; $i<($maxday+$startday); $i++) { $day = ($i - $startday + 1); if($day == $today){ $day = "<b>".($i - $startday + 1)."</b>"; } else { $day = ($i - $startday + 1); } if(($i % 7) == 0 ) echo "<tr>\n"; if($i < $startday) echo "<td></td>\n"; else echo "<td align='center' valign='middle' height='20px'> <a href=\"test.php\" STYLE=\"TEXT-DECORATION: NONE\">". $day . "</td>\n"; if(($i % 7) == 6 ) echo "</tr>\n"; } ?> </table> </td> </tr> </table> </div> there you go. Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/#findComment-889342 Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 I didnt notice you add the NEXt and LAST button there, i will have to check the month too.. one sec. Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/#findComment-889358 Share on other sites More sharing options...
zed420 Posted August 3, 2009 Author Share Posted August 3, 2009 phpSensei I thank you ,I thank you and I thank you that was a great help Zed Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/#findComment-889360 Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 Use this one sorry... I just added to check if month in the calender was the current month, so that every month's day wont be bolded. <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <div id="calendar_div" name="calendar_div"> <table width="400"> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td> </tr> <tr> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; $today = date("j"); $month = date("n"); for ($i=0; $i<($maxday+$startday); $i++) { $day = ($i - $startday + 1); if(($day == $today)&&($cMonth == $month)){ $day = "<b>".($i - $startday + 1)."</b>"; } else { $day = ($i - $startday + 1); } if(($i % 7) == 0 ) echo "<tr>\n"; if($i < $startday) echo "<td></td>\n"; else echo "<td align='center' valign='middle' height='20px'> <a href=\"test.php\" STYLE=\"TEXT-DECORATION: NONE\">". $day . "</td>\n"; if(($i % 7) == 6 ) echo "</tr>\n"; } ?> </table> </td> </tr> </table> </div> Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/#findComment-889361 Share on other sites More sharing options...
zed420 Posted August 3, 2009 Author Share Posted August 3, 2009 Thank you phpSensei Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/#findComment-889366 Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 Thank you phpSensei Np ... click the solved btw Quote Link to comment https://forums.phpfreaks.com/topic/168602-solved-todays-date/#findComment-889370 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.