Witam serdecznie,
mam taką bazę danych:
CREATE TABLE IF NOT EXISTS `cms_multikategorie` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` bigint(20) unsigned NOT NULL,
`position` bigint(20) unsigned NOT NULL,
`left` bigint(20) unsigned NOT NULL,
`right` bigint(20) unsigned NOT NULL,
`level` bigint(20) unsigned NOT NULL,
`title` text COLLATE utf8_unicode_ci,
`type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`zdjecie` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=579316 ;
--
-- Zrzut danych tabeli `cms_multikategorie`
--
INSERT INTO `cms_multikategorie` (`id`, `parent_id`, `position`, `left`, `right`, `level`, `title`, `type`, `zdjecie`) VALUES
(1, 0, 0, 0, 376309, 0, NULL, NULL, ''),
(2, 1, 0, 1, 376306, 1, 'DRZEWO KATEGORII', 'drive', ''),
(39, 2, 0, 10, 175, 2, 'OLEJE I FILTRY', 'folder', ''),
(326850, 326824, 12, 6048, 6049, 6, 'ZWROTNICE, ŁOŻYSKA KÓŁ, PIASTY', 'folder', ''),
(52, 39, 1, 63, 174, 3, 'OLEJE I SMARY', 'folder', ''),
(90, 52, 0, 64, 125, 4, 'oleje silnikowe', 'folder', ''),
(322602, 322601, 7, 378, 379, 6, 'pozostałe', 'folder', ''),
(322037, 323395, 1, 1173, 1510, 3, 'NOWE', 'folder', ''),
(111, 90, 0, 65, 84, 5, 'syntetyczne', 'folder', ''),
(322009, 322001, 7, 100, 101, 6, 'Orlen', 'folder', ''),
(114, 111, 1, 68, 69, 6, 'Castrol', 'folder', ''),
(115, 111, 2, 70, 71, 6, 'Elf', 'folder', ''),
(116, 111, 4, 74, 75, 6, 'Mobil', 'folder', ''),
(117, 111, 6, 78, 79, 6, 'Shell', 'folder', ''),
(322008, 322001, 3, 92, 93, 6, 'Lotos', 'folder', ''),
(322007, 322001, 8, 102, 103, 6, 'pozostałe', 'folder', ''),
(322000, 111, 5, 76, 77, 6, 'Orlen', 'folder', ''),
(322001, 90, 1, 85, 104, 5, 'półsyntetyczne', 'folder', ''),
(322002, 322001, 1, 88, 89, 6, 'Castrol', 'folder', ''),
(322003, 322001, 2, 90, 91, 6, 'Elf', 'folder', ''),
(322004, 322001, 4, 94, 95, 6, 'Mobil', 'folder', ''),
(322005, 322001, 5, 96, 97, 6, 'Shell', 'folder', ''),
(233, 323395, 0, 665, 1172, 3, 'UŻYWANE', 'folder', ''),
(234, 233, 3, 1004, 1171, 4, 'KOŁA DOJAZDOWE', 'folder', ''),
(433, 233, 0, 666, 833, 4, 'FELGI ALUMINIOWE', 'folder', ''),
(434, 433, 3, 729, 768, 5, '16"', 'folder', ''),
(237, 233, 2, 1002, 1003, 4, 'CZUJNIKI CIŚNIENIA', 'folder', ''),
(238, 323458, 2, 1531, 1532, 3, 'KOŁPAKI', 'folder', ''),
(239, 234, 0, 1005, 1014, 5, '13\\"', 'folder', ''),
(270, 264, 0, 1028, 1029, 6, '3x112', 'folder', ''),
(269, 264, 6, 1040, 1041, 6, '5x100', 'folder', ''),
(268, 264, 4, 1036, 1037, 6, '4x114,3', 'folder', ''),
(244, 239, 0, 1006, 1007, 6, '4x98', 'folder', ''),
(245, 239, 1, 1008, 1009, 6, '4x100', 'folder', ''),
(246, 239, 2, 1010, 1011, 6, '4x108', 'folder', ''),
(247, 239, 3, 1012, 1013, 6, '4x114,3', 'folder', ''),
(439, 433, 0, 667, 676, 5, '13"', 'folder', ''),
(438, 433, 2, 689, 728, 5, '15"', 'folder', ''),
(437, 433, 6, 831, 832, 5, 'pozostałe', 'folder', ''),
(436, 433, 1, 677, 688, 5, '14"', 'folder', ''),
(435, 433, 4, 769, 806, 5, '17"', 'folder', ''),
(267, 264, 3, 1034, 1035, 6, '4x108', 'folder', ''),
(266, 264, 2, 1032, 1033, 6, '4x100', 'folder', ''),
(265, 264, 1, 1030, 1031, 6, '4x98', 'folder', ''),
(264, 234, 2, 1027, 1066, 5, '15\\"', 'folder', ''),
(263, 258, 4, 1024, 1025, 6, '5x100', 'folder', ''),
(258, 234, 1, 1015, 1026, 5, '14\\"', 'folder', ''),
(259, 258, 0, 1016, 1017, 6, '4x98', 'folder', ''),
(260, 258, 1, 1018, 1019, 6, '4x100', 'folder', ''),
(261, 258, 2, 1020, 1021, 6, '4x108', 'folder', '');
chciałbym w możliwie najwydajniejszy sposób wygenerować w oparciu o taką bazę menu w formie - Kategoria 1 – podkategoria 1 – podkategoria 2 ---- podpodkategoria 1 ---- podpodkategoria 2 ---- podpodkategoria 3 – podkategoria 3 … … Czyli im poziom niżej tym więcej “-”. aktualnie kombinuję z takim kodem:
try {
$tablicaA = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE level = '2' ORDER by id ASC;");
if (isset($tablicaA)) {
foreach ($tablicaA as $wynA => $warttA) {
if ($warttA['id'] !=325193){
$select = null;
if ($webid['1'] == $warttA['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttA['title']));
$wlktab = 0; $wlktab = count($tablicaA);
echo"$warttA[title] (XXXXXX)";
////////
if ($select != "") {
try {
$tablicaB = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttA[id]' ORDER by id ASC;");
if (isset($tablicaB)) {
foreach ($tablicaB as $wynB => $warttB) {
$select = null;
if ($webid['2'] == $warttB['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttB['title']));
echo"-$warttB[title]";
if ($select != "") {
$tablicaC = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttB[id]' ORDER by id ASC;");
if (isset($tablicaC)) {
foreach ($tablicaC as $wynC => $warttC) {
$select = null;
if ($webid['3'] == $warttC['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttC['title']));
echo"--$warttC[title]";
if ($select != "") {
$tablicaD = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttC[id]' ORDER by id ASC;");
if (isset($tablicaD)) {
foreach ($tablicaD as $wynD => $warttD) {
$select = null;
if ($webid['4'] == $warttD['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttD['title']));
echo"---$warttD[title]";
if ($select != "") {
$tablicaE = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttD[id]' ORDER by id ASC;");
if (isset($tablicaE)) {
foreach ($tablicaE as $wynE => $warttE) {
$select = null;
if ($webid['5'] == $warttE['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttE['title']));
echo"-----$warttE[title]";
if ($select != "") {
$tablicaF = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttE[id]' ORDER by id ASC;");
if (isset($tablicaF)) {
foreach ($tablicaF as $wynF => $warttF) {
$select = null;
if ($webid['6'] == $warttF['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttF['title']));
echo"-----$warttF[title]";
if ($select != "") {
$tablicaG = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttF[id]' ORDER by id ASC;");
if (isset($tablicaG)) {
foreach ($tablicaG as $wynG => $warttG) {
$select = null;
if ($webid['7'] == $warttG['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttG['title']));
echo" $warttG[title]";
if ($select != "") {
$tablicaH = $ms->query_select("SELECT id, title, parent_id FROM " . $GLOBAL['bfprzed'] . "multikategorie WHERE parent_id = '$warttG[id]' ORDER by id ASC;");
if (isset($tablicaH)) {
foreach ($tablicaH as $wynH => $warttH) {
$select = null;
if ($webid['8'] == $warttG['id'])
$select = " style=\"color: #ff0000;\" ";
$shortname = przyjazny_string(baza_odczyt($warttH['title']));
echo" $warttH[title]";
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
} catch (Exception $error) {
echo 'Komunikat: ' . $error->getMessage() . '
Plik: ' . $error->getFile() . '
Wiersz: ' . $error->getLine() . '
IP: ' . $_SERVER['REMOTE_ADDR'] . ' | LINK: ' . $_SERVER['REQUEST_URI'] . '
' . $error->getTraceAsString();
}
}
////////
}
}}
} catch (Exception $error) {
echo 'Komunikat: ' . $error->getMessage() . '
Plik: ' . $error->getFile() . '
Wiersz: ' . $error->getLine() . '
IP: ' . $_SERVER['REMOTE_ADDR'] . ' | LINK: ' . $_SERVER['REQUEST_URI'] . '
' . $error->getTraceAsString();
}
[/code]
ale niestety mam dużo danych w bazie danych i menu wczytuje mi się dłuuuuugo
Macie może jakiś pomysł jak to zrobić lepiej??
Northwest