I have a two tables:
people_en: id, name
people_es: id, name
(please, dont bother about normalization. the design is normalized. the tables are much more complex than this but this is just a way to simplify my problem).
I then have a stored procedure:
CREATE PROCEDURE myproc(lang char(2))
BEGIN
set @select = concat('SELECT * FROM ', lang, ' limit 3');
PREPARE stm FROM @select;
EXECUTE stm;
DEALLOCATE PREPARE stm;
SET @cnt = FOUND_ROWS();
SELECT @cnt;
IF @cnt = 3 THEN
//Here I need to loop through the rows
ELSE
//Do something else
END IF;
END$$
More or less, the logic in the procedure is:
If the select gives 3 rows, then we have to loop through the rows and do something with the value in each row. Otherwise somwthing else (not important what, but I put this to make you understand that I need to have an if statement before looping.
I have seen and read about cursors, but couldnt find much for selects created by concat (does it matter?) and especially created with a prepared statement. How can I iterate through the result list and use the values from each row? Thanks.