|
|||
![]()
Hallo.
Ich habe folgende Datenbank: Tabelle category_product: Code:
category_id, category_pointer, category_name_de, cateogry_name_en 1, 0, 'Hauptebene 1', 'Top Level 1' 2, 0, 'Hauptebene 2', 'Top Level 2' 3, 0, 'Hauptebene 3', 'Top Level 3' 4, 1, 'Unterebene 1 von Hauptebene 1', 'Sub Level 1 from Top Level 1' 5, 1, 'Unterebene 2 von Hauptebene 1', 'Sub Level 2 from Top Level 1' Tabelle produkt: Code:
produkt_id, product_category, product_name_de, product_... 1, '1#2,3,4,5', 'Testprodukt 1', ... 2, '4#5', 'Testprodukt 2', ... 3, '7#2,3', 'Testprodukt 3', ... 4, '5#2,3', 'Testprodukt 4', ... Hauptkategorie#Unterkategorie,Unterkategorie, usw. Mir ist irgendwie kein besserer Weg eingefallen, aber warscheinlich hätte man das auch auf product_main_category und product_sub_category aufteilen können.. egal. Ich möchte jetzt eine Abfrage bauen, welche folgendes liefert: Code:
Hauptebene 1, Unterebene 1, Produkt 1 NULL, NULL, Produkt 2 NULL, Unterebene 2, Produkt 3 NULL, NULL, Produkt 4 NULL, NULL, Produkt 5 Hauptebene 2, Unterebene 1, Produkt 6 NULL, NULL, Produkt 7 Code:
SELECT cat1.category_id AS main_category_id, cat2.category_id AS sub_category_id, cat1.category_name_de AS main_category_name_de, cat2.category_pointer, cat2.category_name_de AS sub_category_name_de, product.*, LEFT(product.product_category, LOCATE('#', product.product_category)-1) AS product_category_main_id FROM category_product AS cat1 INNER JOIN category_product AS cat2 ON cat2.category_pointer = cat1.category_id INNER JOIN product ON LEFT(product.product_category, LOCATE('#', product.product_category)-1) = cat2.category_id ORDER BY main_category_name_de, sub_category_name_de, product_name_de ![]() Nur leider liefert es alles doppelt und dreifach :/ Das Ergebniss sieht so aus: Code:
Hauptebene 1, Unterebene 1, Produkt 1 Hauptebene 1, Unterebene 1, Produkt 2 Hauptebene 1, Unterebene 2, Produkt 3 Hauptebene 1, Unterebene 2, Produkt 4 Hauptebene 1, Unterebene 2, Produkt 5 Hauptebene 2, Unterebene 1, Produkt 6 Hauptebene 2, Unterebene 1, Produkt 7 Kann mir da jemand helfen? mfg trequ PS: Bin bis Montag in Urlaub, werd als vorher nicht antworten können. ![]() |
Sponsored Links |
|
|||
![]()
Hallo,
ehrlich gesagt habe ich nicht ganz verstanden was du da eigentlich erreichen willst. Nur folgendes: Um eine sinnvolle Zuordnung von Produkten zu Kategorien zu erreichen solltest du lieber noch eine Tabelle prod_cat einführen, welche mindestens die Felder produkt_id und category_id enthält. |
Sponsored Links |
![]() |
Themen-Optionen | |
Ansicht | |
|
|
![]() |
||||
Thema | Autor | Forum | Antworten | Letzter Beitrag |
Layout-Problem Suche hilfe | mottzi | CSS | 1 | 26.03.2010 23:30 |
Suche Hilfe zum "Bild coden" | HerzogIgzorn | (X)HTML | 27 | 17.02.2010 15:00 |
Ein herzliches hallo von einem neuen, auf der suche nach hilfe | probe | Site- und Layoutcheck | 2 | 24.09.2007 14:42 |
BITTE UM HILFE! Suche schon seit Monaten ein nach einem PHP SCRIPT! | snooktunes | Serveradministration und serverseitige Scripte | 11 | 09.07.2007 16:30 |
[MySQL] Suche | lomtas | Serveradministration und serverseitige Scripte | 9 | 13.07.2005 08:44 |