I have two tables one table contain category name,category_id other table contain category_id and parent_id. so the data is stored like that for particular category_id we need to find parent_id until parent_id is null.
It simply like category/leafcategory/l2/l3.
to find the parent of l3 we have to loop the table untill the parent_id is null. and where the parent_id is null that category_id is parentcategory.