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

Fill in the blank below...

So i have the following challenge: "I have the following statement prepared SELECT * FROM users LIMIT ? . Fill in what I should put in to the last parameter of the bindParam call __________."

I'm not understanding what's being asked of me.

I understand the LIMIT function, but i don't understand what exactly they want me to write on this challenge. Maybe it's a language barrier thing, but honest to god, i'm at a loss here...

For example i have the following code:

$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);
        $results->execute();

So looking at this code, what are they asking?

Tyvm in advance for your help.

Bruno

2 Answers

Hello Bruno,

This is the bindParam statement in full: bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable [, int $data_type [, int $length [, mixed $driver_options ]]] )

The parameters in the square brackets are not necessary so in this case the statement is used in this way: bool PDOStatement::bindParam ( mixed $parameter , mixed &$variable , int $data_type) So the third parameter is the data type of the value that will be placed in place of the question mark .

LIMIT requires a whole number in other words integer. So the last parameter should be PDO::PARAM_INT and thats the answer to the challenge.

Hope this will help Kristian

Ah that makes sense. Still think the question should be phrased differently. But that's my opinion :P Either way, thx for the help, this was really doing my head in since i wasn't really understanding the question...

David Rynn
David Rynn
10,554 Points

I agree with the OP. Pretty vague question, I had no idea what was being asked. Thanks for the answer though.