serbestgezer Posted June 30, 2009 Share Posted June 30, 2009 Hi all, I couldnt figure it out to make actual date in bold. Any help much appreciated! Thanks <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "October", "September", "November", "December"); ?> <?php if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); ?> <?php $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; } ?> <link href="table.css" rel="stylesheet" type="text/css"> <table width="100%" border="0" cellpadding="0" cellspacing="1" class="mainTableTOC"> <tr> <td class="monthYearRowTOC" colspan="7"><table width="100%"> <tr> <td width="11%" class="monthYearTextTOC"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>"><<</a></td> <td width="80%" class="monthYearTextTOC"><div align="center"><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></div></td> <td width="9%" class="monthYearTextTOC" style="text-align: right;"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>">>></a></td> </tr> </table></td> </tr> <tr class="dayNamesTextTOC"> <td class="dayNamesRowTOC">Sunday</td> <td class="dayNamesRowTOC">Monday</td> <td class="dayNamesRowTOC">Tuesday</td> <td class="dayNamesRowTOC">Wednesday</td> <td class="dayNamesRowTOC">Thursday</td> <td class="dayNamesRowTOC">Friday</td> <td class="dayNamesRowTOC">Saturday</td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; $today = date("d"); for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ) echo "\n".'<tr class="rowsTOC">'; if($i < $startday) echo '<td class="sOtherTOC"></td>'. "\n" ; else echo "\n" .'<td class="s20TOC"><div class=daynumTOC>'. ($i - $startday + 1) . '</div>'."\n".'<div class="titleTOC">data from mysql</div></td>'; if(($i % 7) == 6 ) { echo "\n</tr>";} } if($startday > 4) { $maxtable = 42; } else { $maxtable = 35; } $blank = $maxday + $startday; $draw = $maxtable - $blank; $i = 1; while($i <= $draw) { echo '<td class="sOtherTOC"></td>'; $i++; } echo "</tr></table>"; ?> Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/ Share on other sites More sharing options...
jmr3460 Posted June 30, 2009 Share Posted June 30, 2009 Did you write this, is there any readme files with it? I am very new but it would seem to me that you should be able to use your $today variable in an internal style sheet somehow if that is what this variable is used for. I am interested in learning more about this calendar. How large is the Style sheet, can you post it? Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866131 Share on other sites More sharing options...
flyhoney Posted June 30, 2009 Share Posted June 30, 2009 Here is a push in the right direction: <?php for ($i = 0; $i < ($maxday + $startday); $i++) { // This should set $bold == TRUE if $i is the current day of the week $bold = (bool) ($i == date('j')); if (($i % 7) == 0 ) echo "\n".'<tr class="rowsTOC">'; if ($i < $startday) echo '<td class="sOtherTOC"></td>'. "\n" ; else echo "\n" .'<td class="s20TOC"><div class=daynumTOC>'. ($i - $startday + 1) . '</div>'."\n".'<div class="titleTOC">data from mysql</div></td>'; if (($i % 7) == 6 ) echo "\n</tr>"; } Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866133 Share on other sites More sharing options...
serbestgezer Posted June 30, 2009 Author Share Posted June 30, 2009 it doesnt doing anything Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866141 Share on other sites More sharing options...
flyhoney Posted June 30, 2009 Share Posted June 30, 2009 it doesnt doing anything Did you even try to figure out what I did in that example? PHP has an awesome date() function. It returns a formatted date. date('j') returns the current day of the week as a number from 1 - 31. In the for loop that prints each day of the month, I'm checking to see if the current day of the week matches $i. i.e. <?php $bold = (bool) ($i == date('j')); Adding the (bool) casts the comparison to a boolean, so now, you can check to see if the current number in the for loop is the current day of the week. Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866142 Share on other sites More sharing options...
serbestgezer Posted June 30, 2009 Author Share Posted June 30, 2009 it doesnt doing anything Did you even try to figure out what I did in that example? PHP has an awesome date() function. It returns a formatted date. date('j') returns the current day of the week as a number from 1 - 31. In the for loop that prints each day of the month, I'm checking to see if the current day of the week matches $i. i.e. <?php $bold = (bool) ($i == date('j')); Adding the (bool) casts the comparison to a boolean, so now, you can check to see if the current number in the for loop is the current day of the week. I understand that, I never used (bool) before and when I use this code, it doesnt make the current date bold. Am I missing something? Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866150 Share on other sites More sharing options...
MatthewJ Posted June 30, 2009 Share Posted June 30, 2009 On a side note... September comes before October. $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September","October" , "November", "December"); Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866152 Share on other sites More sharing options...
flyhoney Posted June 30, 2009 Share Posted June 30, 2009 I'm letting you take the extra step of actually making the day bold. I've written the code that determines whether or not the current day that is being displayed _should_ be bold. i.e. if $bold === TRUE, then $i is the current day of the week, if $bold === FALSE, $i is not. Link to comment https://forums.phpfreaks.com/topic/164191-php-calendar/#findComment-866153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.