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 trialAdam maitland
Courses Plus Student 211 PointsVery 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;
}
?>
2 Answers
Jacob Mishkin
23,118 PointsYou 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
Courses Plus Student 211 PointsThanks Jacob not sure how I missed that! but its still not working, I can't see any reason to why its not working
Jacob Mishkin
23,118 PointsI'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.
Lindsay Sauer
12,029 Pointstime() 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();
}
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsedited to format code