-2

I was trying this one but doesn't seem to work for me. I took reference from here. And below is my code:

$today = date('Y-m-d');
$date = new DateTime();

$R1D2 = $date->setISODate($year,$week,1)->format('Y-m-d');

<td width="14.285%" <?php if ($R1D2 = $today): ?> style="background:#EEEEEE" <?php endif ?>>some content here </td>

The result is, all the cells changes its background even if it's not equal with $today

Richelle
  • 119
  • 1
  • 15

1 Answers1

5

if ($R1D2 = $today):

You are actually setting $R1D2 as $today. Please change that line to:

if ($R1D2 == $today):

FluffyKitten
  • 13,824
  • 10
  • 39
  • 52
IsThisJavascript
  • 1,726
  • 2
  • 16
  • 25
  • thanks! I didn't realize that `=` and `==` have different functions. – Richelle Oct 16 '17 at 14:10
  • 1
    It's a useful mechanic that you may take advantage of in the future – IsThisJavascript Oct 16 '17 at 14:11
  • 3
    @Richelle You even got a third, `===` which has yet another meaning. Read the post this was marked as a duplicate of. These are quite important to know... – M. Eriksson Oct 16 '17 at 14:14
  • @MagnusEriksson I'll take note of this. Many thanks. – Richelle Oct 16 '17 at 14:18
  • If you are a person, which probably often does this type of mistake, you can use "yode-speaking"-style. Like (`true == $var`), since if you miss a equal sign there, you get a syntax error. In your case tho, this would not have made a difference. I made myself always use yoda-talk and I never made this error again (in over 8 years :P) – Manuel Mannhardt Oct 16 '17 at 14:25