n0one Posted October 28, 2008 Report Share Posted October 28, 2008 Sveiki! Ir mysql tabula, tabula paredzeta dokumentiem un folderiem (ja skataas no ftp, tad visi faili ir vienaa mapee, sakartoshana pa mapeem notiek peec mysql) struktuura : id, vecaaka_id, menu_id, adrese (ja fails, deafult 'url'), tips (dok vai fails)... darbiibas princips kaa parastam file explorer neskaitaami daudz mapes daudzos limenjos viena zem otras. probleema saakaas tur: ja man nepiecieshams dzeest mapi, tad ir jasavac visi id (ari apaksmapem un failiem,) pa vairaakiem liimenjiem... menu_id ir sadaljas id, kas visiem failiem un mapeem buus vienaads ... paareejais mainaas. nedaudz dati: ID v_id m_id tips adr 18 0 7 dok url 19 18 7 dok url 20 18 7 dok url 21 18 7 dok url 22 0 7 dok url 23 22 7 dok url 24 21 7 dok url 25 19 7 file aaa_2008.doc 26 19 7 file bbb_2008.doc tatad ja es gribeetu zdzest mapi ar ID 18, man buutu jaasalasa masiivas ar ID $mas=array(18,19,20,21,24,25,26) ... palaik netieku talak par $mas=array(18,19,20,21) ja eju dziljak ka lai tieku atpakalj un saku ar citu mapi ??? Link to comment Share on other sites More sharing options...
andrisp Posted October 28, 2008 Report Share Posted October 28, 2008 Rekursiju māki lietot ? function x() { x(); } x(); Link to comment Share on other sites More sharing options...
n0one Posted October 28, 2008 Author Report Share Posted October 28, 2008 (edited) Taatad Varu izveidot funkciju kuru var izmantot n(reizes) pashaa funkcijaa Paraknjaashos php manuaalii ... <?php $level=0; //saakumaa ... pirmo mapi ar kuru dariishana atziimee kaa startu... function mape($v_id, $level) { $q = mysql_query('SELECT * FROM ok '.'WHERE v_id="'.$v_id.'";'); while ($array_dok = mysql_fetch_array($q)) { array_push($array_dok[id]); mape($row['id'], $level+1); // dodamies pakalj naakamajaam ... } } ?> Edited October 28, 2008 by n0one Link to comment Share on other sites More sharing options...
martins256 Posted October 28, 2008 Report Share Posted October 28, 2008 Funckija, kura atgriezīs visu dzēšamo elementu id. function rekursiivs_del($parent_id) { $return = array(); $result = mysql_query("SELECT id,tips FROM tabula WHERE parent_id = $parent_id"); while($row = mysql_fetch_assoc($result)) { #ja tips ir folderis if($row['tips'] == 1) { $return[] = $row['id']; $r = rekursiivs_del($row['id']); $return = array_merge($return,$r); } #nav folderis ir fails else { $return[] = $row['id']; } } return $return; } Link to comment Share on other sites More sharing options...
n0one Posted October 28, 2008 Author Report Share Posted October 28, 2008 Skaidrs Paldies Jums :) Jaa tagad zinu, kas ir rekursija un kaa to pielietot... Vieniigais, kas shajaa gadiijumaa notiks ar tiem daudzajiem selektiem ciklaa, kaads buus noslogojums datubaazei, un ja es tajaa vietaa to visu jau pasniegtu kaa masiivu, nevis visu laiku selekteetu, vai tad funkcija nedarbotos aatraak? Man tas ir svariigi, jo hostings ir no Amerikas Link to comment Share on other sites More sharing options...
andrisp Posted October 28, 2008 Report Share Posted October 28, 2008 Nu rekursija, it sevišķi ja tā darbojas ap db, ir resursrijīga padarīšana. Es gan nesapratu tavu pēdējo jautājumu, bet dzēšanas kveriju tu pēc tam vienu vari uzrakstīt. Link to comment Share on other sites More sharing options...
martins256 Posted October 28, 2008 Report Share Posted October 28, 2008 Vēl jau vari taisīt kādu sql procedūru vai ko tādu. tad tas ātrums palielinātos. Link to comment Share on other sites More sharing options...
n0one Posted October 28, 2008 Author Report Share Posted October 28, 2008 es domaaju, ja tieshi to select queriju es arpus funkcijas panjemtu, un tad funkcijai iedotu masiivu ar kuru stradat, lai nav visu laiku vieni un tie pashi dati jaselektee.... dzeeshana pati jau par sevi. Link to comment Share on other sites More sharing options...
andrisp Posted October 28, 2008 Report Share Posted October 28, 2008 Ā, nu vari izselektēt visas rindas, un tad rekursīvi strādāt ar šīm rindām. Bet tad gan iesaku selektēt tikai id un parent_id kolumnas. Link to comment Share on other sites More sharing options...
n0one Posted October 28, 2008 Author Report Share Posted October 28, 2008 Taa arii dariishu ;) Paaldies! Link to comment Share on other sites More sharing options...
Recommended Posts