Can you please help me with looping inside a MySql event?
I did this event in MySql, but I guess I'm missing something. It works if I supply a limit = 1, which means it isn't looping thru the thing. How can I do that?
This works. (For only one record) BEGIN
DECLARE c VARCHAR(2);
DECLARE vElm INT(10);
DECLARE vType TINYINT(1);
select distinct(country) into c from votes limit 1;
select votedElm, voteType into vElm, vType from votes where country = c limit 1;
IF vType = 0 THEN
update likes set votes = votes+1 where id = vElm and country = c and type = 10;
ELSE IF vType = 1
update likes set votes = votes-1 where id = vElm and country = c and type = 10;
END IF;
END
This will not. Note: The limit 1 has been removed BEGIN
DECLARE c VARCHAR(2);
DECLARE vElm INT(10);
DECLARE vType TINYINT(1);
select distinct(country) into c from votes;
//Need to loop here. This returns multiple records.
select votedElm, voteType into vElm, vType from votes where country = c;
//Need to loop here too. This too returns multiple records.
IF vType = 0 THEN
update likes set votes = votes+1 where id = vElm and country = c and type = 10;
ELSE IF vType = 1
update likes set votes = votes-1 where id = vElm and country = c and type = 10;
END IF;
END
How is looping done inside a MySql event?
Thanks