litt Posted October 26, 2005 Report Share Posted October 26, 2005 Datubāzē glabājās ieraksti, kuriem ir id, title, par - parentID, ch - children count. Ar kverija palīdzību no bāzes dabonu šādu masīvu (ORDER BY par, title) Array ( [0] => Array ( [id] => 1 [par] => 0 [ch] => 2 [title] => Main page ) [1] => Array ( [id] => 4 [par] => 1 [ch] => 0 [title] => mape 1 ) [2] => Array ( [id] => 5 [par] => 1 [ch] => 2 [title] => mape 2 ) [3] => Array ( [id] => 6 [par] => 5 [ch] => 1 [title] => apaksh1 ) [4] => Array ( [id] => 8 [par] => 5 [ch] => 0 [title] => apaksh2 ) [5] => Array ( [id] => 7 [par] => 6 [ch] => 0 [title] => sub ) ) Rezultātā vajag šādu "koku" no šī masīva Array ( [0] => Array ( [id] => 1 [par] => 0 [ch] => 2 [title] => Main page [chld] => Array ( [0] => Array ( [id] => 4 [par] => 1 [ch] => 0 [title] => mape 1 [chld] => Array ( ) ) [1] => Array ( [id] => 5 [par] => 1 [ch] => 2 [title] => mape 2 [chld] => Array ( [0] => Array ( [id] => 6 [par] => 5 [ch] => 1 [title] => apaksh1 [chld] => Array ( [0] => Array ( [id] => 7 [par] => 6 [ch] => 0 [title] => sub [chld] => Array ( ) ) ) ) [1] => Array ( [id] => 8 [par] => 5 [ch] => 0 [title] => apaksh2 [chld] => Array ( ) ) ) ) ) ) ) Ir kāds veids kā ar PHP to visu ātri apstrādāt un dabūt vēlamo rezultātu (izejas masīvs var būt liels, tapēc svarīga ir ātrdarbība)? Link to comment Share on other sites More sharing options...
fassko Posted October 26, 2005 Report Share Posted October 26, 2005 Uzraksti iisaak, kaa tev vajag sakaartot, nevis iekopee shitaadus gaisa gabalus! Link to comment Share on other sites More sharing options...
[Ya] Posted October 26, 2005 Report Share Posted October 26, 2005 heh tu apskaidro kas ko noziimee, tad varbut vareetu pastaastiit .... Link to comment Share on other sites More sharing options...
litt Posted October 26, 2005 Author Report Share Posted October 26, 2005 Rezultātā vajag koku, kur katra parenta masīva elements 'chld' ir masīvs ar konkrētā parenta childs (koka dziļums var būt bezgalīgs) Link to comment Share on other sites More sharing options...
[Ya] Posted October 26, 2005 Report Share Posted October 26, 2005 (edited) taatad pateikshu kaa tas ir, bet skriptu raksti pats, sakārto array secībā pēc [par]... ņemam tos kuriem nav [par] meklējam ieksh pārējiem array kur meklējamā array [par] = esošā array [id] taisam jaunu key [chld] liekam iekšā to array kuram [par] = esosā array [id] un tā uz priekšu tikai! nav man tik daudz laika lai rakstītu to skriptu Edited October 26, 2005 by [Ya] Link to comment Share on other sites More sharing options...
v3rb0 Posted October 26, 2005 Report Share Posted October 26, 2005 + pie kaartotaa masiiva var piekombineet klaat kaadu viltiigaaku mekleesanas algoritmu pa masiivu, lai mekleejot nav visi masiiva elementi jaapaarlasa. Link to comment Share on other sites More sharing options...
hmnc Posted October 26, 2005 Report Share Posted October 26, 2005 es parasti gan taisu ar diviem masīviem (indeksi + parent nodes) un ar rekursiju izbrauc visiem cauri. ja nemaldos tad iterāciju skaitam bija jābūt vienādam ar kopējo ierakstu skaitu, neatceros (ja nē tad +1) Link to comment Share on other sites More sharing options...
Analgiins Posted October 26, 2005 Report Share Posted October 26, 2005 forumaa jau par to bija runaats: http://php.lv/f/index.php?showtopic=1972&st=0&p=13293 var pamekleet arri kaut ko citu Link to comment Share on other sites More sharing options...
Recommended Posts