Packets out of order. Error retrieving data from MariaDB

Just to add to this, rather use a temp table with an auto-incrementing id field. Then you can use a while loop if you know the size of the table (select count(1) as numRecords from tbl_x).

(Pseudo code)
WHILE (i <= numRecords)

i++;
END