Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Adam maitland
PLUS
Adam maitland
Courses Plus Student 211 Points

Very simple php timer (looking for an explanation to why its not working)

Why can't this code work ?

<?php 

$timeGet = time();
$timeM = time()+10;
$time = date('H:i:s', $timeGet);

 while($time != $timeN) {

        echo $time;

    }

?>

edited to format code

2 Answers

You should look at the conditional statement.

<?php
$timeGet = time();
$timeM = time()+10; 
$time = date('H:i:s', $timeGet);

while($time != $timeN) { // you do not have a variable named $timeN,

//change to $timeM
?>
Adam maitland
Adam maitland
Courses Plus Student 211 Points

Thanks Jacob not sure how I missed that! but its still not working, I can't see any reason to why its not working

I'm not sure, but from reading the documentation for php I believe you are not setting everything you need in order for this to work.

here is I think a better explanation than what I can provide.

php docs

time() returns a Unix timestamp, and your $time variable is formatted as a date. So you're comparing a date-formatted string to a timestamp int:

 While (06:54:19 != 1455893669)

In your while loop, try comparing $timeGet to $timeM. Also, you'll need to change the value of $timeGet in the while loop, otherwise you'll be in an infinite loop.

 while($timeGet < $timeN) {
       $timeGet = time();
 }