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 Enhancing a Simple PHP Application Paginating a List: Controller Adjusting Invalid Numbers

You are including too many numbers in category (c). Please try again.


require_once('model.php'); $numbers = get_numbers();

$count_less_than_one           = 0;
$count_between_one_and_thousand = 0;
$count_greater_than_thousand    = 0;

foreach ($numbers as $number) {

  if($number < 1){
    $count_less_than_one += 1;
  if($number >=1  && $number<= 1000){
    $count_between_one_and_thousand += 1;
    $count_greater_than_thousand += 1;




Cannot see anything wrong with this code.

2 Answers

Hi Andreas,

You want your second if to be an else if This way it's part of the starting if block.

Suppose the number is -5. The 1st if condition will be true and that count will be incremented. Then it's going to check against the second if and that will be false so it will execute the else and that count will be incremented even though the number was -5.

By making it an else if then it will skip that block and the else block.

cool thanks Jason was cracking my head as to why the code wasnt working but didnt think to put a elseif because most of the tie you can get away with not putting an elseif but two if statements and then an else. But it worked thanks