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

Gareth Redfern
Gareth Redfern
36,217 Points

PHP Code Challenge Help

Hi, I am really stuck on this code challenge can anyone help please:

http://teamtreehouse.com/library/adjusting-invalid-numbers

4 Answers

Nick Stellato
seal-mask
.a{fill-rule:evenodd;}techdegree
Nick Stellato
Front End Web Development Techdegree Student 33,994 Points

Gareth,

I took a look at what you posted. It seems that you need to add some if/else statements in order to control which count variable gets increased.

'''php <?php

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 is _____ */
    $count_less_than_one += 1;

    $count_between_one_and_thousand += 1;

    $count_greater_than_thousand += 1;
}

include('view.php'); ?> '''

Gareth Redfern
Gareth Redfern
36,217 Points

Ahh O.K. thanks Nick, I have given this a try but it fails:

$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;
        }

                if ($number < 1000) {
        $count_greater_than_thousand += 1;
        }
    }

Well Gareth you've solved the answer yourself you only made a slight typo fault.

Look at your last if block, it doens't say "greater" (>) than 1000 it actually says "less"(<) than 1000

Gareth Redfern
Gareth Redfern
36,217 Points

Ahh perfect thanks, J.L. so close but that fixed it!