Reputation: 211
i'm an absolute beginner in php, and i'm just trying to make a simple if else statement. Please take a look at this:
<?php
$currentDate = echo date("Y");
$startup = '2013';
if ($startup = $currentDate) {
?>
© 2013 Blue Box 22
<?php } else { ?>
© 2013 - <?php echo date("Y"); ?> Blue Box 22
<?php } ?>
As you can probably read, i'm just checking if the current year is equal to the startup year, and then let it display accordingly. I presume there's something wrong in my syntax as that part of my page isn't rendering.
Thank you for your help!
Upvotes: 0
Views: 162
Reputation: 1
This means assigning "=" This means comparing "=="
This should help you with your code. :)
Upvotes: 0
Reputation: 15656
Instead of:
if ($startup = $currentDate) {
it should be
if ($startup == $currentDate) {
Moreover, instead of using
$currentDate = echo date("Y");
try:
$currentDate = date("Y");
Upvotes: 11
Reputation: 1679
<?php
$currentDate = date("Y");//echo removed, never use while comparison
$startup = '2013';
if ($startup == $currentDate) {// comparison is done by ==, = make assignment
?>
© 2013 Blue Box 22
<?php } else { ?>
© 2013 - <?php echo date("Y"); ?> Blue Box 22
<?php } ?>
Upvotes: 0
Reputation: 70728
You've assigned the variable in the if
statement, not compared. Comparisons are done with the ==
operator.
if ($startup == $currentDate) {
}
Which means if (startup is equal to the current date then do this)
Upvotes: 0