Reputation: 863
I am connecting to an SQL database in my PHP script and am having trouble with the LIMIT
command:
$result = mysql_query("
SELECT *
FROM product
WHERE `category` like \"" . $_GET['category'] . "\"
LIMIT 0, 16
");
This all works, except that if I only have 10 rows then $result
contains rows 0~10 and then 0~6 as well.
I am using a a while loop while($row = mysql_fetch_assoc($result))
to check if there is a result and then run an action. Is there any way of having it limit the select statement to only show rows 0~10?
Upvotes: 1
Views: 1296
Reputation: 50976
$result = mysql_query("SELECT * FROM product
WHERE `category` like '" . mysql_real_escape_string($_GET['category']) . "' LIMIT 0, 10");
is it what are you looking for? It will give you ten rows maximally..
Additionally, please read this article about SQLi
Upvotes: 1