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 Duplicating SKU as an Array Element

Zeljko Porobija
Zeljko Porobija
11,491 Points

Images gone

I no longer see images on shirts/ and index/ pages, but I have them on shirt/ page (when I click view details). I know that we have differences in web addresses, but I have no clue where to search for the solution. I mean, products.php and index.php are just copy-paste of the tutorial.

When I var_dump $product I get this: ["img"]=> string(24) "img/shirts/shirt-108.jpg Obviously, this is the wrong path. How to make it right?

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Zeljko. FYI, I moved your second question into this one. For future reference, you can edit your question, or add a comment rather than adding a new question. People will see them separately, so your second question didn't make any sense.

3 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Zeljko,

Can you paste your code from shirts/ and index/? I'd like to see what your img tags look like. It looks like they're not pointing to the correct location, but it's impossible to know why without seeing your code.

Thanks,

-Greg

Zeljko Porobija
Zeljko Porobija
11,491 Points
index.php
<?php 

require_once("inc/config.php");

$pageTitle = "Unique T-shirts designed by a frog";
$section = "home";
include(ROOT_PATH . 'inc/header.php'); ?>
        <div class="section banner">

            <div class="wrapper">

                <img class="hero" src="<?php echo BASE_URL; ?>img/mike-the-frog.png" alt="Mike the Frog says:">
                <div class="button">
                    <a href="<?php echo BASE_URL; ?>shirts">
                        <h2>Hey, I&rsquo;m Mike!</h2>
                        <p>Check Out My Shirts</p>
                    </a>
                </div>
            </div>

        </div>

        <div class="section shirts latest">

            <div class="wrapper">

                <h2>Mike&rsquo;s Latest Shirts</h2>

                <?php include(ROOT_PATH . "inc/products.php"); ?>
                <ul class="products">
                    <?php 

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

            </div>

        </div>

<?php include(ROOT_PATH . 'inc/footer.php') ?>```
Zeljko Porobija
Zeljko Porobija
11,491 Points
shirts.php
<?php

    require_once("../inc/config.php");
    require_once(ROOT_PATH . "inc/products.php");

?><?php 
$pageTitle = "Mike's Full Catalog of Shirts";
$section = "shirts";
include(ROOT_PATH . 'inc/header.php'); ?>

        <div class="section shirts page">

            <div class="wrapper">

                <h1>Mike&rsquo;s Full Catalog of Shirts</h1>

                <ul class="products">
                    <?php foreach($products as $product) { 
                            echo get_list_view_html($product);
                        }
                    ?>
                </ul>

            </div>

        </div>

<?php include(ROOT_PATH . 'inc/footer.php') ?>