clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 818513 fiddles created (9187 in the last week).

CREATE TABLE spr_type ( id int NOT NULL AUTO_INCREMENT, id_parent int DEFAULT NULL, order_ int DEFAULT NULL, name varchar(255) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE = INNODB, AUTO_INCREMENT = 9, AVG_ROW_LENGTH = 2048, CHARACTER SET utf8mb4, COLLATE utf8mb4_0900_ai_ci; ALTER TABLE spr_type ADD CONSTRAINT spr_type_ibfk_1 FOREIGN KEY (id_parent) REFERENCES spr_type (id); INSERT INTO spr_type VALUES (1, NULL, 1, 'aaaaa'), (2, NULL, 2, 'ggggg'), (3, 1, 2, 'eeeee'), (4, NULL, 3, 'ffff'), (5, 1, 1, 'ttttsfasfa'), (6, 5, 2, 'ggggggg'), (7, 5, 1, 'рррррррррррррр'), (8, 2, 1, '000000000000'); SELECT * FROM spr_type;
id id_parent order_ name
1 1 aaaaa
2 2 ggggg
3 1 2 eeeee
4 3 ffff
5 1 1 ttttsfasfa
6 5 2 ggggggg
7 5 1 рррррррррррррр
8 2 1 000000000000
 hidden batch(es)


SET @a = 0; SELECT concat(GROUP_CONCAT(d SEPARATOR ' '),'</ul>') dd FROM ( WITH RECURSIVE Rec (id, name, id_parent, order_, ll) AS (SELECT id, name, IFNULL(id_parent, 0), CAST(order_ AS char(200)), 1 FROM spr_type WHERE id_parent IS NULL UNION ALL SELECT spr_type.id, spr_type.name, spr_type.id_parent, CONCAT(Rec.order_, spr_type.order_), CHAR_LENGTH(CONCAT(Rec.order_, spr_type.order_)) FROM Rec JOIN spr_type ON Rec.id = spr_type.id_parent) SELECT CASE WHEN @a < ll THEN CONCAT('<ul><li>',name,'</li>') WHEN @a > ll THEN CONCAT('</ul>','<li>',name,'</li>') WHEN @a = ll THEN CONCAT('<li>',name,'</li>') END AS d, @a := ll AS x , id FROM Rec ORDER BY order_ ) AS ff
dd
<ul><li>aaaaa</li> <ul><li>ttttsfasfa</li> <ul><li>рррррррррррррр</li> <li>ggggggg</li> </ul><li>eeeee</li> </ul><li>ggggg</li> <ul><li>000000000000</li> </ul><li>ffff</li></ul>
 hidden batch(es)