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 ?, ?");

So looking at this code, what are they asking?

Tyvm in advance for your help.


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.