You're if statements have a typo:
if ($current_sec = '1')
Is always true. Try:
if ($current_sec == '1')
Question
I am trying to get the time (seconds) from the server and then associate this to a student name:
$info = getdate();
$sec = $info['seconds'];
$current_sec = $sec;
echo $current_sec;
echo " | ";
if ($current_sec == '1') {echo 'John';}
else if ($current_sec == '2') {echo 'Mary';}
else if ($current_sec == '3') {echo 'Bill';}
~~~
else if ($current_sec == '60') {echo 'Bob';}
echo " | ";
echo $current_sec;
However I seem to get the same result each time no matter when I refresh the page:
15 | John | 1
where 15 is the actual seconds.
I would be grateful for any help.
Solution
You're if statements have a typo:
if ($current_sec = '1')
Is always true. Try:
if ($current_sec == '1')
OTHER TIPS
Because comparison operator is ==
, not =