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

pagination uncaught error call to a member function bindParam() on null

I was following aloong with the pagination and I got did everything just like the code said to after I put the function in with the

$count = $results->fetchColumn(0);

I went to look at everything and it was gone. I do not have a 'bad query' remark. but I come up with 'Uncaught Error: Call to function bindParam() on null

function get_catalog_count($category = null) {
    $category = strtolower($category);
    include 'connection.php';
    try {
        $sql = "SELECT COUNT(media_id) FROM Media";
        if (!empty($category)) {
            $result = $db->prepare($sql . ' WHERE LOWER(category) = ?'); // category always lower case
            $results->bindParam(1, $category, PDO::PARAM_STR);//1 category, filter

        } else {
            $results = $db->prepare($sql);
        }
        $result->execute();
    }catch(Exception $e){
        echo 'Bad Query';
    }
    $count = $results->fetchColumn(0);// fetch column and 0 for first column.
    return $count;
}

any thoughts?

1 Answer

Patricia Hector
Patricia Hector
42,901 Points

Hi there; the problem may be in the fact that you are working with the variable $result in the singular form, and also $results in the plural form. Once you fix it everything should be ok.

thank you for pointing out my small error!!