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

Andrew Merrick
Andrew Merrick
20,151 Points

Adding HTML Markup

Randy or any other moderator:

I'm currently on the Adding HTML Markup video in the Paginating a List: Model and View section of the PHP course: http://teamtreehouse.com/library/programming/enhancing-a-simple-php-application/paginating-a-list-model-and-view/adding-html-markup.

I've set up the while function on the shirts.php file so that only 8 shirts are displayed on each page and there are button links to navigate the pages. However, with my code, I can see the links but the shirts are missing! I checked the CSS file and pagination is there. I don't know what is wrong since I've triple-checked that my code is the same as in the video. Since this is a long post I will submit my code in a new post.

Any help would be appreciated! Thanks!

Andrew Merrick
Andrew Merrick
20,151 Points

<?php

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

    $current_page = $_GET["pg"];

    if (empty($_GET["pg"])) {
        $current_page = 1;
    } else {
        $current_page = $_GET["pg"];
    }
    $current_page = intval($current_page);

    $total_products = get_products_count();
    $products_per_page = 8;
    $total_pages = ceil($total_products / $products_per_page);

    if ($current_page > $total_pages) {
        header("Location: ./?pg=" . $total_pages);
    }

    if ($current_page < 1) {
        header("Location: ./");
    }

    $start = (($current_page - 1) * $products_per_page) + 1;
    $end = $current_page * $products_per_page;
    if ($end > $total_products) {
        $end = $total_products;
    }

    // $products = get_products_subset($start,$end);

?><?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>

                <div class="pagination">

                    <?php $i = 0; ?>
                    <?php while ($i < $total_pages) : ?>
                        <?php $i += 1; ?>
                        <?php if ($i == $current_page) : ?>
                            <span><?php echo $i; ?></span>
                        <?php else : ?>
                            <a href="./?pg=<?php echo $i; ?>"><?php echo $i; ?></a>
                        <?php endif; ?>
                    <?php endwhile; ?>

                </div>

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

            </div>

        </div>

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

1 Answer

Andrew Merrick
Andrew Merrick
20,151 Points

Nevermind! I had a piece of code that was commented out for some reason but when I uncommented it the shirts returned.

My bad!