Einzelnen Beitrag anzeigen
  #4  
Alt 19.10.2010, 18:24:38
thomas_w thomas_w ist offline
Junior Member
 
Registriert seit: Aug 2010
Alter: 14
Beiträge: 395
AW: NESTED SETS in XML - Gruppierung von Elementen

Also Deine Lösung #1 sieht ja eigentlich ganz aus.

Für die Lösung #2 habe ich an folgende Tabellen gedacht, aber so richtig einfach wird der SQL nicht. Auf die schnelle habe ich keine Lösung gefunden.

Also ..

Code:
CREATE TABLE IF NOT EXISTS `tree` (
  `id` int(11) NOT NULL,
  `tag` varchar(100) NOT NULL,
  `lft` int(11) NOT NULL,
  `rgt` int(11) NOT NULL,
  `desc` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Daten für Tabelle `tree`
--

INSERT INTO `tree` (`id`, `tag`, `lft`, `rgt`, `desc`) VALUES
(1, 'A', 1, 16, 'content A'),
(2, 'B', 2, 3, 'content B'),
(3, 'C', 4, 13, 'content C'),
(4, 'D', 5, 12, 'content D'),
(5, 'E', 6, 7, 'content E'),
(6, 'F', 8, 11, 'content F'),
(7, 'G', 9, 10, 'content G'),
(8, 'H', 14, 15, 'content H'),
(11, 'C1', 4, 13, 'content C1');


-- Sub Elemente - Sub-Elemente für G

CREATE TABLE IF NOT EXISTS `tree_sub` (
  id INT NOT NULL,
  id_tree INT NOT NULL, 
  tag varchar(100) NOT NULL,
  lft INT NOT NULL,
  rgt INT NOT NULL,
  description text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


INSERT INTO tree_sub (id, id_tree, tag, lft, rgt, description) VALUES
(1, 7, 'G2', 9, 10, 'content G1'),
(2, 7, 'G3', 9, 10, 'content G2');
Grüße
Thomas
__________________
Die SQL-Backstube
Bietet Rezepte, Lösungen und ausführliche Beispiele rund um gesundes SQL und zufriedene Datenbanken.
Mit Zitat antworten