Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

Giacomo

index.php
<?php

    $recommendations = array();

?><html>
<body>

    <h1>Flavor Recommendations</h1>

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

</body>
</html>

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!

Giacomo

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

Cheers,

Giacomo