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 Adding Search: Controller & View Accounting for Empty Results

Giacomo Alberini
Giacomo Alberini
9,548 Points

Code Challenge not working: typo error?

Hi guys!

I've got this problem with this PHP Code Challenge.

I just tried it in my localhost configuration and it worked properly (both the version completely surrounded by <?php ?> code and the one with one php tag for each line).

I really don't know where my error is, even because I know that the code runs properly.

There's maybe some problem with the formatting and maybe the system does not understand my code, but I really don't know how to go on with the Challenge.

And I've noticed that it's not the first time during this PHP Track that I find errors in the Challenges, and I'm not able to understand when it's a problem of mine or a system's one.

Hope you help me find some solutions

Thank you for the help!



    $recommendations = array();


    <h1>Flavor Recommendations</h1>

      <?php if (!empty($recommendations)) { ?>
            <?php foreach($recommendations as $flavor) { ?>
                <li> <?php echo $flavor; ?> </li>
              <?pho } ?>
            <?php } ?>


3 Answers

Hi giacomo,

You have a syntax error in your code. You have pho instead of php for the closing brace on the foreach

<?pho } ?>

Once you fix that you will get a more helpful error message of:

Bummer! The unordered list tags appear even when the array is empty. Place those tags inside a conditional that uses the empty function.

The idea here behind this first task is that you don't want to output the ul tags if the array is empty. Whereas, your code is outputting them no matter what.

If you move the if block outside the ul then you will only output the ul if the array has something in it.

Let me know if you're still stuck or have further questions about this.

Giacomo Alberini
Giacomo Alberini
9,548 Points

Hi Jason!

Thank you!

You've just provided the right solutions. The initial code was right in my localhost but I did not figured out that the system wanted not to see any <ul> tag! Thank you!

Can you please (if I'm not asking too much :) ) go to this thread and try to find another (great) solution to this other problem? https://teamtreehouse.com/forum/php-relative-path-include-code-challenge

I'm really grateful to you!

Cheers and thank you again!


You're welcome.

The other thread doesn't have a link to the challenge but the accepted best answer seems right based on the instructions and from what I remember.

You would need to go up 2 folders and then down in the "config" folder.

Can you post a link to the challenge in the other thread?

Giacomo Alberini
Giacomo Alberini
9,548 Points

Sure! I've just posted the link in the other thread!

Your help is really welcome!

I post the link to that discussion here: https://teamtreehouse.com/forum/php-relative-path-include-code-challenge