Reputation: 77
I am trying to get rows from table - specific range of rows to be clear. My query looks like this (just part of the code):
SET @i=0;
SELECT * FROM images WHERE (@i:=@i+1) BETWEEN 1 AND 10;
What is does is get row number of rows and returns rows, whose row number is in given range. When I run this query in phpmyadmin, I can see the result of the query (the actual rows in that range), however the number of rows from query is 0. I am pretty sure the problem is with this part
WHERE (@i:=@i+1)
I have searched throught other answers, but the reason was always in php, not the query itself.
Upvotes: 0
Views: 477
Reputation: 781255
When you use phpMyAdmin, each query opens a new database connection, and user variables don't persist between connections. Set the variable in a subquery that you join:
SELECT i.*
FROM images AS i
CROSS JOIN (SELECT @i := 0) AS x
WHERE (@i := @i + 1) BETWEEN 1 AND 10;
Upvotes: 2