According to the child nodes to find the parent node function, who help to take a look at what problems,
DROP FUNCTION GetParentName;
The CREATE FUNCTION ` GetParentName ` (` nodeId ` int) RETURNS a varchar (400) CHARSET utf8
The BEGIN
DECLARE parentId INT.
DECLARE parentName VARCHAR (400);
DECLARE the pId INT.
DECLARE num INT.
The SET parentId=99999;
The SET parentName=' ';
The SET of pId=` nodeId `;
Select count (1) INTO num from niche_intentresources where ID=pId;
If num=0 then the set parentId=0;
The else
The select ParentID INTO ParentID from niche_intentresources where ID=pId;
The select ` Title ` INTO parentName from niche_intentresources where ID=pId;
end if;
WHILE parentId & lt;> 0 DO
The set of pId=parentId;
The select ParentID INTO ParentID from niche_intentresources where id=pId;
The select CONCAT_WS (' - ', ` Title `, parentName) INTO parentName from niche_intentresources where ID=pId;
END the WHILE;
RETURN parentName;
END