Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,848 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