| |

VerySource

 Forgot password?
 Register
Search
View: 1457|Reply: 7

Table of parent-child structure transformed into a hierarchical Web page

[Copy link]

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2021-3-1 10:30:01
| Show all posts |Read mode
Now there is such a problem, there is a Table in the database of SQL SERVER

Column A Column B Column C
1 ABC 0
2 BCD 1
3 CDE 1
4 DEF 3
5 EFG 3


If it’s displayed on the Web, it’s a structure like this
ABC BCD
ABC CDE DEF
ABC CDE EFG

How to achieve. Thank you
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 United States

Post time: 2021-3-1 13:00:01
| Show all posts
I'm too stupid, I still don't understand what to do
But it seems to be related to the logic of the program, so control it in the program
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

 Author| Post time: 2021-3-1 13:15:01
| Show all posts
The above table is a parent-child structure.
If it is displayed on the web, it is impossible to directly display the parent-child structure, because it seems very difficult to understand.
So show it as a hierarchical structure.
The second table is to display the highest level of ABC on the first level. Then expand according to the parent-child table to get the second level, the third level...
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2021-3-1 13:30:02
| Show all posts
Finally understand it, it is best to implement it in the program
If there are only two levels, SQL can also be used, if there are unlimited levels, SQL is powerless
In terms of these two levels alone:
SELECT tb.idname, tb_1.idname AS Expr1, tb_2.idname AS Expr2
FROM tb tb_2 RIGHT OUTER JOIN
      tb tb_1 ON tb_2.parentid = tb_1.id RIGHT OUTER JOIN
      tb ON tb_1.parentid = tb.id
WHERE (tb.parentid = 0)
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

 Author| Post time: 2021-3-1 14:00:01
| Show all posts
What if there is another layer below? Because I really don't know how many levels there are!
ID IDNAME Parent ID
1 ABC 0
2 BCD 1
3 CDE 1
4 DEF 3
5 EFG 3
6 FGH 5
7 GHI 5
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2021-3-1 14:15:01
| Show all posts
If there are multiple levels of classification, it can only be controlled in the program. In fact, it is also very simple, just simple process logic control
Reply

Use magic Report

1

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

 Author| Post time: 2021-3-1 14:30:02
| Show all posts
Can you give me an example. Thank you!
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2021-3-1 17:30:01
| Show all posts
It depends on what language you use, but in the final analysis, it is the movement operation of the record set, which is more troublesome but not difficult
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list