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 trialBen Os
20,008 PointsItems are not displayed at all when filtered by category.
I guess my problem deals with index.php and catalog.php files (and maybe also with functions.php).
When I go to the main navigation menu on my site and click a category, nothing occurs. The page is almost empty.
Site: http://port-80-mkqxe69shv.treehouse-app.com/
Snapshot: https://w.trhou.se/cvi4jrrf27
1 Answer
Benjamin Larson
34,055 PointsHi Ben,
You can always check your code against the code that Alena Holligan uses in the videos. Here is the complete array_category() function. I think your biggest problem was not using the strtolower method when comparing the category strings. You should also check to make sure the category is not null, as the first part of the function accomplishes:
function array_category($catalog, $category)
{
if ($category == null)
{
return array_keys($catalog);
}
$output = array();
foreach ($catalog as $id => $item)
{
if (strtolower($category) == strtolower($item["category"]))
{
$output[] = $id;
}
}
return $output;
}
Ben Os
20,008 PointsBen Os
20,008 PointsHi, I checked the code several times... I didn't use the strlower function since I always use lowercase letters in the firstplace... Or shell I say - I tend to do so.
Benjamin Larson
34,055 PointsBenjamin Larson
34,055 PointsThe difficulty is that in this example, the array is hard-coded with category strings that do use uppercase values. It's a good practice when comparing strings, especially those that involve user input that you can't predict, to use a function like strlower(). Obviously you don't want to do this when checking something case-sensitive, like usernames and passwords.