大侠们,帮帮忙啊,如何才能按顺序列出表中的数据啊?
表数据在后面,如何才能显示
大概型如:
ID
3
38
39
53
5
23
24
25
53
54
55
56
57
58
77
7
9
21
100
132
133
前面的空格不管它,主要是这样树型的顺序,即某一项的位置先比较其祖先元素的排序,同等的再比较自身.
谢谢
/********************
CREATE TABLE `test` (
`categories_id` int(6) NOT NULL default '0 ',
`parent_id` int(6) NOT NULL default '0 '
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `test` VALUES (3, 0);
INSERT INTO `test` VALUES (5, 0);
INSERT INTO `test` VALUES (7, 0);
INSERT INTO `test` VALUES (9, 0);
INSERT INTO `test` VALUES (102, 9);
INSERT INTO `test` VALUES (14, 5);
INSERT INTO `test` VALUES (97, 131);
INSERT INTO `test` VALUES (114, 106);
INSERT INTO `test` VALUES (85, 144);
INSERT INTO `test` VALUES (86, 0);
INSERT INTO `test` VALUES (21, 9);
INSERT INTO `test` VALUES (22, 131);
INSERT INTO `test` VALUES (23, 5);
INSERT INTO `test` VALUES (24, 5);
INSERT INTO `test` VALUES (25, 5);
INSERT INTO `test` VALUES (34, 144);
INSERT INTO `test` VALUES (104, 131);
INSERT INTO `test` VALUES (38, 3);
INSERT INTO `test` VALUES (39, 3);
INSERT INTO `test` VALUES (100, 9);
INSERT INTO `test` VALUES (44, 158);
INSERT INTO `test` VALUES (46, 131);
INSERT INTO `test` VALUES (47, 141);
INSERT INTO `test` VALUES (48, 131);
INSERT INTO `test` VALUES (49, 140);
INSERT INTO `test` VALUES (50, 131);
INSERT INTO `test` VALUES (51, 131);
INSERT INTO `test` VALUES (52, 9);
INSERT INTO `test` VALUES (53, 5);
INSERT INTO `test` VALUES (54, 5);
INSERT INTO `test` VALUES (55, 5);
INSERT INTO `test` VALUES (56, 5);
INSERT INTO `test` VALUES (57, 5);
INSERT INTO `test` VALUES (58, 5);
INSERT INTO `test` VALUES (96, 146);
INSERT INTO `test` VALUES (87, 131);
INSERT INTO `test` VALUES (88, 145);
INSERT INTO `test` VALUES (89, 145);
INSERT INTO `test` VALUES (90, 144);
INSERT INTO `test` VALUES (91, &