bschultz Posted June 28, 2010 Share Posted June 28, 2010 I'm trying to highlight "today" in a calendar....but EVERY date shows up in the highlights background color. Any ideas? Thanks. <?php for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) { $rowcounter ++; $todayis = date('Y-m-d'); if ($todayis = "$thisyear-$thismonth-$counter") { echo "\t\t<td bgcolor='#CCCCCC' valign='top'><span class='style3'><strong><font color='#990000'>$counter</font><br /></span></strong>"; } else { echo "\t\t<td valign='top'><span class='style3'><strong><font color='#990000'>$counter</font><br /></span></strong>"; } } ?> $thisyear-$thismonth-$counter are defined earlier...and if I echo them, they do display properly. Here's the whole code...if that makes it easier. <?php // Set month and year from $_GET variables if they exist, otherwise generate current // month and year from date() function $thismonth = isset($_GET['thismonth']) ? $_GET['thismonth'] : date('m'); $thisyear = isset($_GET['thisyear']) ? $_GET['thisyear'] : date('Y'); // Validate month if (preg_match('/^[0-1][0-9]$/', $thismonth) === 0 || $thismonth < 1 || $thismonth > 12) { $thismonth = date('m'); $thisyear = date('Y'); } else { } // Validate year if (preg_match('/^[0-9]{4}$/', $thisyear) === 0) { $thismonth = date('m'); $thisyear = date('Y'); } else { } $testdate = $thisyear . '-' . $thismonth . '-01'; $last_month = date('m', strtotime('-1 month', strtotime($testdate))); $last_year = date('Y', strtotime('-1 month', strtotime($testdate))); $next_month = date('m', strtotime('+1 month', strtotime($testdate))); $next_year = date('Y', strtotime('+1 month', strtotime($testdate))); // find out the number of days in the month $numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $thismonth, $thisyear ); // create a calendar object $jd = cal_to_jd( CAL_GREGORIAN, $thismonth, date( 1 ), $thisyear ); // get the start day as an int (0 = Sunday, 1 = Monday, etc) $startday = jddayofweek( $jd , 0 ); // get the month as a name $monthname = jdmonthname( $jd, 1 ) ?> </span> <table> <tr> <td colspan="7" class="style4"><div align="center"><strong> <?php echo "<div class='style3'><a href='calendar.php?thismonth=$last_month&thisyear=$last_year'>Previous Month <<<<<<</a> "; if($thismonth=='01') echo('January'); else if($thismonth=='02') echo('February'); else if($thismonth=='03') echo('March'); else if($thismonth=='04') echo('April'); else if($thismonth=='05') echo('May'); else if($thismonth=='06') echo('June'); else if($thismonth=='07') echo('July'); else if($thismonth=='08') echo('August'); else if($thismonth=='09') echo('September'); else if($thismonth=='10') echo('October'); else if($thismonth=='11') echo('November'); else if($thismonth=='12') echo('December'); else echo ""; echo " $thisyear <a href='calendar.php?thismonth=$next_month&thisyear=$next_year'>Next Month >>>>>></a>"; ?></div></strong></div></td> </tr> <tr> <td width="142" class="style4"><strong>Sunday</strong></td> <td width="142" class="style4"><strong>Monday</strong></td> <td width="142" class="style4"><strong>Tuesday</strong></td> <td width="142" class="style4"><strong>Wednesday</strong></td> <td width="142" class="style4"><strong>Thursday</strong></td> <td width="142" class="style4"><strong>Friday</strong></td> <td width="142" class="style4"><strong>Saturday</strong></td> </tr> <tr> <?php // put render empty cells $emptycells = 0; for( $counter = 0; $counter < $startday; $counter ++ ) { echo "\t\t<td> </td>\n"; $emptycells ++; } // renders the days $rowcounter = $emptycells; $numinrow = 7; for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) { $rowcounter ++; $todayis = date('Y-m-d'); if ($todayis = "$thisyear-$thismonth-$counter") { echo "\t\t<td bgcolor='#CCCCCC' valign='top'><span class='style3'><strong><font color='#990000'>$counter</font><br /></span></strong>"; } else { echo "\t\t<td valign='top'><span class='style3'><strong><font color='#990000'>$counter</font><br /></span></strong>"; } //do your normal mysql setup and connection calls $dbc = mysql_pconnect($host, $username, $password); mysql_select_db($db,$dbc); //now get stuff from a table $sql = "SELECT * FROM $table WHERE date='$thisyear-$thismonth-$counter'"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "<img src='/images/line.gif' alt='line' /><br />"; echo "<span class='style4'>$row[time]"." <br /><strong>$row[sport]"." $row[visitor]"." at "."$row[home]</strong><br />"; echo "$row[ump1] "."$row[ump2] "."$row[ump3] "."$row[ump4] "."$row[ump5]</span><br />"; echo "<span class='field'>$row[field]</span><br>"."<span class='notes'>$row[notes]</span><br>"; } if (! $matches) { echo "<img src='/images/line.gif' alt='line' /><br />"; } echo ""; $sql = "SELECT * FROM vacation WHERE date='$thisyear-$thismonth-$counter'"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "<br /><span class='style5'>$row[umpire] Off</span>"; } if (! $matches) { echo "<span class='style5'> </span>"; } echo "<br />"; echo "</td>\n"; if( $rowcounter % $numinrow == 0 ) { echo "\t</tr>\n"; if( $counter < $numdaysinmonth ) { echo "\t<tr>\n"; } $rowcounter = 0; } } // clean up $numcellsleft = $numinrow - $rowcounter; if( $numcellsleft != $numinrow ) { for( $counter = 0; $counter < $numcellsleft; $counter ++ ) { echo "\t\t<td> </td>\n"; $emptycells ++; } } ?> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 28, 2010 Share Posted June 28, 2010 Use double equal signs for comparisons, use single equal sign for assignment. Quote Link to comment Share on other sites More sharing options...
bschultz Posted June 28, 2010 Author Share Posted June 28, 2010 Thank you!!! Quote Link to comment 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.