Answer the question
In order to leave comments, you need to log in
What query should be written to display the nesting level for a menu item?
The menu table is simple name, url, parent (name, where to go and the parent menu item) ...
What query should be written to display another level - the nesting level for the menu item?
Answer the question
In order to leave comments, you need to log in
select * from tbl_menu
then a loop in which a data structure is formed that is convenient for display
Here, catch it. Here the syntax is in T-SQL, but it is easy to remake it for another DBMS. On Habré there is an article about recursion. there and about MySQL the recursion is shown.
go
with myrec (ProdName,id,idParent,levell) as
(
Select CONVERT(varchar(255), ProdName),id,idParent,0 from Products where idParent=-1
union ALL
Select CONVERT(varchar(255),d.ProdName+ '\'+a.ProdName) as ProdName,a.id,a.idParent,levell+1 from Products a
inner join myrec d on d.id=a.idParent)
select b.ProdName as ProdName,b.id,b .idParent,levell from Products a
right join myrec b on a.id = b.idparent
where b.id=(select idparent from Products where id=35)
go
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question