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 Build a Simple PHP Application Working With Functions Displaying Only Four Shirts

Sandro Meschiari
Sandro Meschiari
18,418 Points

loop shirts homepage

<?php include("inc/products.php"); ?>

            <ul class="products">

                <?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 = get_list_view_html($product_id,$product) . $list_view_html;
                        }
                    }
                    echo $list_view_html;
                ?>  
            </ul>

this is my code but i have a problem in the shirts.php is perfectly working but in the home page i can see the layout of the page correctly but there no shirts display, can anybody have a look at my code and see where i am wrong cos i ve checked it over and over and it seems ok, maybe a fresh eye will do!! thanks

Nicole Archambault
Nicole Archambault
27,853 Points

Are you getting any error messages from the PHP server, or is the section just not rendering? If there are no errors, you'll want to make sure your server is configured to show them right on the page. (I know MAMP doesn't do this by default, at least) I would start there and report your errors.

1 Answer

Jason S
Jason S
16,247 Points

The code you have should display the 4 shirts but in backward order with the last shirt first because you need the list_view_html before the get_list_view_html($product_id, $product) if it's displaying no shirts at all then it's a problem with your other php files