I am trying to use nested loop outer one to access all categories then using that taxID I am querying posts from that tax so that I can assign them ranking as per their category placement.
But I am facing problem that the inner loop "RankingLoop " is only accessing all post results of one taxID then terminate loop and don't loop for other category post if I use Repeat in place of RankingLoop then first record of each taxID loop become accessible. can any body please help to explain problem in my code?
Thank you for help in advance.
DELIMITER $$
CREATE PROCEDURE Catranking__()
Begin
Declare txID INT; Declare txmaxcount INT;
Declare txCount CURSOR FOR SELECT max(term_taxonomy_id) FROM `wp_term_taxonomy` where taxonomy = 'category' and count > 0;
Declare taxonomyIDS CURSOR FOR SELECT term_taxonomy_id FROM `wp_term_taxonomy` where taxonomy = 'category' and count > 0;
open taxonomyIDS; open txCount;
FETCH txCount into txmaxcount;
loop_label: LOOP
FETCH taxonomyIDS into txID;
if txID < (txmaxcount+1) then set @rank=0;
categorywisePostSorting: begin
DECLARE Vranking INT;
DECLARE VPOSTID INT;
Declare RankingArray CURSOR FOR select @rank:=@rank+1 as ranking, POSTID FROM RankingView WHERE term_id = txID order by claimedProducts desc, commentcount desc, pageviews desc;
open RankingArray;
RankingLoop : Loop
FETCH RankingArray into Vranking, VPOSTID;
select VPOSTID;
end Loop RankingLoop;
close RankingArray;
END categorywisePostSorting;
end if;
END LOOP loop_label;
close taxonomyIDS; close txCount;
END$$
DELIMITER ;