zimulis Posted February 20, 2009 Report Share Posted February 20, 2009 (edited) Atsaucoties uz forumu temu http://php.lv/f/index.php?showtopic=3364 Vai kadam ir idejas ka varetu dabut visus viena ID "bernus" visos limenos? Edited February 20, 2009 by zimulis Quote Link to comment Share on other sites More sharing options...
bubu Posted February 20, 2009 Report Share Posted February 20, 2009 To var darīt ar nested set struktūru: http://dev.mysql.com/tech-resources/articl...hical-data.html http://www.developersdex.com/gurus/articles/112.asp Tad visus viena apakšzara bērnus dabūt būs tik vien kā: SELECT node.* FROM tabule AS node, tabule AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND parent.id = $root_id ORDER BY node.lft; Quote Link to comment Share on other sites More sharing options...
zimulis Posted February 20, 2009 Author Report Share Posted February 20, 2009 (edited) Ja bet man ir savadaka DB struktura, man vis notiek pec paren_Id principa, negribetos parprogramet skriptu un partaisit datubazi... Edited February 20, 2009 by zimulis Quote Link to comment Share on other sites More sharing options...
bubu Posted February 20, 2009 Report Share Posted February 20, 2009 Nu to vajadzēja domāt sākumā, pirms taisīt db, kādas būs prasības un kā vajadzēs db izmantot :) Parasta parent_id gadījumā nekas cits kā taisīt n'tos selektus neatliek. Quote Link to comment Share on other sites More sharing options...
zimulis Posted February 20, 2009 Author Report Share Posted February 20, 2009 ta jau tas ir, ka papildus parsibas parasi rodas tad kad viss jau ir gatavs :D Ok domasu ko darit lietas laba.... Quote Link to comment Share on other sites More sharing options...
NiTrino Posted February 20, 2009 Report Share Posted February 20, 2009 (edited) Man te iemētājies viens skripts kā izvadīt rekursīvo tree ar vienu selektu... izmantoju lai ģenerētu nested <ul></ul> http://paste.php.lv/3fbd513581c2910879d577...567fad?lang=php moš noderēs... Edited February 20, 2009 by NiTrino Quote Link to comment Share on other sites More sharing options...
bubu Posted February 20, 2009 Report Share Posted February 20, 2009 Diezgan briesmīgi - it īpaši, ja tabulā būs pavairāk ieraksti. Un kamdēļ tu taisi to pirmo foreach ciklu meklējot to $pid? Masīvam pēc atslēgas var tikt klāt ar kvadrātiekavām: function ShowTree($tree, $pid = 0) { echo "<ul>"; if (array_key_exists($pid, $tree)) { $root = $tree[$pid]; if (count($root) != 0) { foreach ($root as $key => $title) { echo "<li>{$title}"; ShowTree($tree, $key); echo "</li>"; } } } echo "</ul>"; } Quote Link to comment Share on other sites More sharing options...
Delfins Posted February 20, 2009 Report Share Posted February 20, 2009 storētā procedūra ir tas glābiņš Quote Link to comment Share on other sites More sharing options...
bubu Posted February 20, 2009 Report Share Posted February 20, 2009 Un storētā procedūrā nevajadzēs taisīt n'tos kverijus? Quote Link to comment Share on other sites More sharing options...
NiTrino Posted February 20, 2009 Report Share Posted February 20, 2009 bubu: tabulai ar 30 ierakstiem pilnīgi pietiekami :) tūkstošiem ierakstu protams neder... Quote Link to comment Share on other sites More sharing options...
zimulis Posted February 20, 2009 Author Report Share Posted February 20, 2009 nu jā manā gadījumā ir daudz vairāk par 30mit :) Quote Link to comment Share on other sites More sharing options...
Web Developer Posted February 20, 2009 Report Share Posted February 20, 2009 zimulis - tev tiešām ir grūti šeit īsi aprakstīt savu tabulas struktūru un vēlamo rezultātu, ko tev vajag? Nu tā - loģiski? Quote Link to comment Share on other sites More sharing options...
bubu Posted February 20, 2009 Report Share Posted February 20, 2009 Web Developer, kas tev nav skaidrs no tipiskākās parent_id koka struktūras? id, name, parent_id Un ko vajag manuprāt viņš ļoti skaidri pateica - dabūt visus viena ID bērnus visos līmeņos. Tb visus ierakstus konkrētajā apakškokā. Quote Link to comment Share on other sites More sharing options...
Web Developer Posted February 20, 2009 Report Share Posted February 20, 2009 Īsāk sakot visus bērnus vecākam X. parent_id=X - no šejienes arī sākam. Gribot negribot sanāk rekursīvā funkcija - vai to veic serverskripts vai datubāzes kods - kāda starpība? Gan jau, ka atliek vienkārši pamērīt ātrumus un izvēlēties piemērotāko variantu. Quote Link to comment Share on other sites More sharing options...
zimulis Posted March 13, 2009 Author Report Share Posted March 13, 2009 To var darīt ar nested set struktūru: http://dev.mysql.com/tech-resources/articl...hical-data.html http://www.developersdex.com/gurus/articles/112.asp Tad visus viena apakšzara bērnus dabūt būs tik vien kā: SELECT node.* FROM tabule AS node, tabule AS parent WHERE node.lft BETWEEN parent.lft AND parent.rgt AND parent.id = $root_id ORDER BY node.lft; A ja napieciessams izvilkt viena ID visus bernus, mazbernus, mazzmazberbus u.t.t. vardu sakot Visu kas ietilpst saja zara?? Datubaze: ID | Left |right| level Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.