Getting straight to the point. I have let's suppose two tables with fields,
table a: id, parentid, status
table b: id, name
Now i want to get the data in such a form that if an id is selected, check for it's parent id and if the parent id exists (means not 0), then check that parent id's parent id and recursive call until there is an id which has no parentid.
And then i want to show the results as follow. Like if table a has data:
id parentid status
1 0 a
2 1 a
3 2 a
4 0 a
And table b has data:
Now if id 3 is selected i want to show the output like;
And if 4 is selected then;
What i have tried is as follows:
SELECT REPLACE(GROUP_CONCAT(name), ',',-') AS Values,
FROM a as one,
a as two LEFT JOIN b ON two.id = b.id
WHERE two.id = "(Here i get the value)"
I am working on this thing since last two days and can not take it to end. So can any of you kindly help me or can guide me on the proper track please???