Klez Posted March 6, 2008 Report Share Posted March 6, 2008 (edited) ir tabula: ID | parent | name function treeview($pos = false,$atdala = '') { if (!$pos) $pos = 0; $all = db_query("SELECT id,name FROM category WHERE parent=$pos ORDER BY sort ASC"); $count = 0; while ($one = mysql_fetch_row($all)) { echo $atdala.$one[1] . '<br>'; $count++; $has_kids = mysql_fetch_row(db_query("SELECT id,name FROM category WHERE parent=$one[0] ORDER BY sort ASC")); if ($has_kids) treeview($one[0],str_repeat('--',$count)); } } lieta taada ka vinsh laagaa nezimee to koku. divos liimenjos ir ok, bet tālāk nezīmē. kļūda gan jau ka maziņa, bet nevaru atrast ... Edited March 6, 2008 by Klez Link to comment Share on other sites More sharing options...
andrisp Posted March 6, 2008 Report Share Posted March 6, 2008 Tu izsauc funkciju ar diviem parametriem, bet reāli funkcija ņem pretī vienu tikai. Link to comment Share on other sites More sharing options...
Klez Posted March 6, 2008 Author Report Share Posted March 6, 2008 (edited) nu tur bija domaats priekshaa atdaliitaajs, lai redz kaa pa liimenjiem kustas. ir izlabots tur izvadaas shitaa: Mēbeles --vel kresls --kresls ----kresla kaja --krēsla kājas puļķis --zzzzzz --sssss --krēsla atzveltne Santehnika Sīkumi db ir: id parent name sort 1 0 Mēbeles 1 2 1 kresls 2 3 2 kresla kaja 1 4 1 vel kresls 1 5 0 Santehnika 2 6 0 Sīkumi 3 7 3 krēsla kājas puļķis 1 8 3 krēsla atzveltne 2 9 7 zzzzzz 1 10 7 sssss 1 Edited March 6, 2008 by Klez Link to comment Share on other sites More sharing options...
Aleksejs Posted March 6, 2008 Report Share Posted March 6, 2008 (edited) Manuprāt, Tev tas $count arī ir jāpadod. Tobiš pirmo reizi jau izsauc ar count parametru 0. function treeview($pos = false,$count) { if (!$pos) $pos = 0; $all = db_query("SELECT id,name FROM category WHERE parent=$pos ORDER BY sort ASC"); $atdala = str_repeat('--',$count); while ($one = mysql_fetch_row($all)) { echo $atdala.$one[1] . '<br>'; $has_kids = mysql_fetch_row(db_query("SELECT id,name FROM category WHERE parent=$one[0] ORDER BY sort ASC")); if ($has_kids) treeview($one[0],$count+1); } } Edited March 6, 2008 by Aleksejs Link to comment Share on other sites More sharing options...
andrisp Posted March 6, 2008 Report Share Posted March 6, 2008 (edited) Varbūt tad parādi izlaboto, jo meibī vaina ir tieši tur. Moka šitā labāk: <?php function treeview($pos = false, $level = 0) { if (!$pos) $pos = 0; $all = db_query("SELECT id,name FROM category WHERE parent=$pos ORDER BY sort ASC"); $level ++; while ($one = mysql_fetch_row($all)) { echo str_repeat('--', $level).$one[1] . '<br>'; $has_kids = mysql_fetch_row(db_query("SELECT id,name FROM category WHERE parent=$one[0] ORDER BY sort ASC")); if ($has_kids) treeview($one[0], $level); } }; ?> Edited March 6, 2008 by andrisp Link to comment Share on other sites More sharing options...
Klez Posted March 6, 2008 Author Report Share Posted March 6, 2008 (edited) andrisp tavs variants straadaa: --Mēbeles ----vel kresls ----kresls ------kresla kaja --------krēsla kājas puļķis ----------zzzzzz ----------sssss --------krēsla atzveltne --Santehnika --Sīkumi vieniigi palaboju sho rindinju: echo str_repeat('--', $level-1).$one[1] . '<br>'; un sanaak: Mēbeles --vel kresls --kresls ----kresla kaja ------krēsla kājas puļķis --------zzzzzz --------sssss ------krēsla atzveltne Santehnika Sīkumi Edited March 6, 2008 by Klez Link to comment Share on other sites More sharing options...
andrisp Posted March 6, 2008 Report Share Posted March 6, 2008 Vari vienkārši arī kā sākumvērtību tam parametram norādīt -1. Link to comment Share on other sites More sharing options...
Recommended Posts