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 Using PHP with MySQL Limiting Records in SQL Queries Using LIMIT with Offset

Using LIMIT with Offset not working

HELP! I have all the functions working except the get_products_subset. I only get a blank screen with on error message when I try to access the shirts page.

function get_products_subset($positionStart, $positionEnd) { $offset = $positionStart - 1; $rows = $positionEnd - $positionStart + 1;

require(ROOT_PATH . "inc/database.php");

try {
    $results = $db->prepare(
        "SELECT name, price, img, sku, paypal
        FROM products 
        ORDER BY sku 
        LIMIT ?, ?"); 

       $results->bindParam(1, $offset, PDO::PARAM_INT);
       $results->bindParam(2, $rows, PDO::PARAM_INT);
       $resilts->execute();

} catch (Exception $e) {
    echo "Data could not be retrieved from the database.";
    exit;
}

$subset = $results->fetchAll(PDO::FETCH_ASSOC);

return $subset;

}