标题:求助将循环简化为无限循环
取消只看楼主
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
结帖率:87.5%
已结贴  问题点数:20 回复次数:6 
求助将循环简化为无限循环
        sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where parent is null or trim(parent)='' order by dwcd"
        cur.execute(sql)
        tr0=cur.fetchall()
        for s0 in tr0:
            root= QTreeWidgetItem(self.tree)
            root.setText(0,s0[0])
            root.setText(1,s0[1])
            dwh=s0[1]
            sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
            cur.execute(sql)
            tr1=cur.fetchall()
            if bool(tr1):
                for s1 in tr1:
                    child = QTreeWidgetItem(root)
                    child.setText(0, s1[0])
                    child.setText(1, s1[1])
                    dwh = s1[1]
                    sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                    cur.execute(sql)
                    tr2=cur.fetchall()
                    if bool(tr2):
                        for s2 in tr2:
                            child2 = QTreeWidgetItem(child)
                            child2.setText(0, s2[0])
                            child2.setText(1, s2[1])
                            dwh= s2[1]
                            sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                            cur.execute(sql)
                            tr3=cur.fetchall()
                            if bool(tr3):
                                for s3 in tr3:
                                    child3 = QTreeWidgetItem(child2)
                                    child3.setText(0, s3[0])
                                    child3.setText(1, s3[1])
                                    dwh= s3[1]
                                    sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                                    cur.execute(sql)
                                    tr4=cur.fetchall()
                                    if bool(tr4):
                                        for s4 in tr4:
                                            child4 = QTreeWidgetItem(child3)
                                            child4.setText(0, s4[0])
                                            child4.setText(1, s4[1])
                                            dwh= s4[1]
                                            sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                                            cur.execute(sql)
                                            tr5=cur.fetchall()
                                            if bool(tr5):
                                                for s5 in tr5:
                                                    child5 = QTreeWidgetItem(child4)
                                                    child5.setText(0, s5[0])
                                                    child5.setText(1, s5[1])
                                                    dwh= s5[1]
                                                    sql="Select trim(dwmc) as dwmc,trim(dwcd) as dwcd from 单位名称 where trim(parent)='"+dwh+"' order by dwcd"
                                                    cur.execute(sql)
                                                    tr6=cur.fetchall()
                                                    if bool(tr6):
                                                        for s6 in tr6:
                                                            child6 = QTreeWidgetItem(child5)
                                                            child6.setText(0, s6[0])
                                                            child6.setText(1, s6[1])
搜索更多相关主题的帖子: execute parent sql order trim 
2023-04-02 13:45
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
得分:0 
回复 2楼 东海ECS
老师能不能具体一点?谢谢!
2023-04-02 18:42
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
得分:0 
回复 4楼 东海ECS
我还是不太会弄,辛苦老师给列下代码呗?谢谢!谢谢!
2023-04-02 19:20
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
得分:0 
回复 7楼 wp231957
谢谢教师回复,我的想法是TREE层次不受限,有多少个层级就延伸到多少层级,直到都没有子集就结束。
2023-04-03 07:39
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
得分:0 
回复 9楼 wp231957
谢谢您的回复,能新辛苦老师帮助解决一下吗?
2023-04-03 09:54
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
得分:0 
回复 9楼 wp231957
我已经做出来了,谢谢老师!
2023-04-03 15:45
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:266
专家分:15
注 册:2012-7-3
得分:0 
回复 12楼 zxq0103
谢谢!
2023-04-11 20:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-511772-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.100119 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved