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

Code Challenge Separation of Concerns

Task 3 of 4

Next, change the $flavors variable in [index.php] to contain the three most popular flavors. Right now, the controller code calls the function get_recent_flavors() in the model code to get the most recent flavors. (Look through [flavors.php] to find a function that returns the most popular flavors.)

My answer below is wrong? Why? The display shows the correct order of flavors.

  <?php

   // INCLUDE MODEL FILE
    require_once("flavors.php");

  // CONTROLLER CODE
   $flavors = get_flavors_by_likes($number);



      // VIEW CODE
    ?><html>

<body>

<h1>Ye Olde Ice Cream Shoppe</h1>

<p>We sell amazing flavors of ice cream.</p>

<h2>Most Popular Flavors</h2>

<ul>
<?php
    foreach ($flavors as $flavor) {
        echo "<li>" . $flavor["name"] . "</li>";
    }
?>
</ul>

</body> </html>

3 Answers

Yes, that helps. Missed that little detail.

I am trying to do the same but for some reason it is not working for me. please help

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

The instructions say that the page should show the three most popular flavors. When I preview the page with your code, it looks like it is showing six flavors.

Does that help?

I am lost in this one. I am not sure how should i do it.