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 Refactoring the Codebase Separating Concerns: MVC

refactoring the Codebase challenge 4/4

"<?php

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

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

// 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"] ." "."+"."likes". "</li>";
    }
?>
</ul>

</body> </html> "

names of flavors are visible but the likes

3 Answers

Austin Davis
Austin Davis
23,939 Points

Based on your code I'm assuming you're getting an error stating that the number of likes aren't being displayed.-- To display the number of likes follow the same logic your using to display the flavor name. In your code you are using the key name via $flavor["name"] to get the value that is the flavor name...and should have a similar statement to get the likes. If you need to- click on the tab at the top to look at flavors.php and consider what key is needed to access value for "likes".

Kazimierz Matan
Kazimierz Matan
13,257 Points

How about something like that:

echo "<li>" . $flavor["name"] ." +". $flavor["????"]. "</li>";

Put proper value instead of ???? (check in model).

I got that I forgot the array, it is so good to get answer very descriptive, thanx Austin and Kazimierz

I just need $flavors ["likes"]