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

General Discussion

PHP Function Displaying Only Four Shirts

Hi ,

1 Answer

Looks like there was a problem in displaying your post! Please ask your question again (including what challenge you're working on and what code you have so far) so the community can help you out.

Hi, I'm trying to follow Nick's tutorial but, at this point, the home page doesn't display four shirts. In fact, it displays four yellow shirts, three gray shirts, two teal shirts and one orange shirt - a total of twelve shirts on the home page!

Here is my code, on the index.php page:

<?php 
                $total_products = count($products);
                $position = 0;
                $list_view_html = "";
                foreach($products as $product_id => $product) { 
                    $position = $position + 1;
                    if ($total_products - $position < 4) {
                        $list_view_html = $list_view_html . get_list_view_html($product_id, $product);
                    }
                    echo $list_view_html;
                }
            ?>

Where am I going wrong?

Many thanks in advance. I look forward to your reply.

Ess

Did I say twelve, shirts? I meant ten.

Did I say Nick? I meant Randy!

Geez! What's wrong with me?!