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 PHP Arrays and Control Structures PHP Loops Do While Looping

Why do i only get 1919 instead all the hundred years before?

<?php
$currentYear = date('Y');
$year = $currentYear - 100;

while (++$year <= $currentYear) {
  echo $year . "<br /<\n";
  $year++;
}
?>

4 Answers

Antonio De Rose
Antonio De Rose
20,885 Points

nope. yours to mine, is the same in terms of your first edition, generally, if you read my notes, you'd be able to do it, my notes are commented issue is in this line

<?php
echo $year . "<br /<\n";
//it has to be like the below
echo $year . "<br />";

Ok silly me, didnt see the echo at the end of the line haha. Now it works but im a bit confused because in the video Alena writes both line break they even discuss this on another question here :https://teamtreehouse.com/community/why-do-i-need-both-br-and-n

Antonio De Rose
Antonio De Rose
20,885 Points

because, you have got an error

<?php
$currentYear = date('Y');
$year = $currentYear - 100;

while (++$year <= $currentYear) {
  echo $year . "<br /<\n"; // here is the error , try this, echo $year . "<br />";
  $year++;
}

//by the way, you will not be able to see, 100 years, instead 50 years only, as you are incrementing by 2
//which in return will skip every alternative year.

?>

Dont really see the diference and i copy and paste it and still only get 1919:/

Literally just copied yours, does it work well for you ?

Antonio De Rose
Antonio De Rose
20,885 Points

yeap, you could use both together

not like the way you have used, cause, I think there is a type, closing bracket for br is mistaken with another opening bracket.

<?php

//your way
echo $year . "<br /<\n"; 

//the correct way
echo $year . "<br />\n";

Ok i see it now thanks alot