Cibiņš Posted June 17, 2012 Report Share Posted June 17, 2012 Man ir rekursijas f-ja kas taisa foršu parent un child sazarojumu. Der poh vai uz dropdown-menu vai sitemap. bet runa ir par sitemap. Bet tā nav problēma. Problēma ir TIKAI viena ID uzlikšana uz galvenā <ul>. Respektīvi man sazarojums veidojas <ul id="MenuBar1"> <li>Zars 1 <ul id="MenuBar1"> <li>Zars 1.1</li> <li>Zars 1.2</li> <li>Zars 1.3</li> </ul> </li> <li>Zars 2 <ul id="MenuBar1"> <li>Zars 2.1</li> <li>Zars 2.2</li> <li>Zars 2.3</li> </ul> </li> <li>Zars 3</li> <li>Zars 4</li> </ul> bet vajag lai ir <ul id="MenuBar1"> <li>Zars 1 <ul> <li>Zars 1.1</li> <li>Zars 1.2</li> <li>Zars 1.3</li> </ul> </li> <li>Zars 2 <ul> <li>Zars 2.1</li> <li>Zars 2.2</li> <li>Zars 2.3</li> </ul> </li> <li>Zars 3</li> <li>Zars 4</li> </ul> kur pazūd tie id="MenuBar1" apakšzariem. Lai ir tikai uz galvenā <ul>. Zemāk ir tā rekursijas f-ja. function sitemap2($pid2){ $sql2="SELECT * FROM pg_menu WHERE parent_id=".intval($pid2)." AND status = '1' ORDER BY position ASC;"; $res2=mysql_query($sql2); if(mysql_num_rows($res2)<1){ return ''; $axa=false; } $s2='<ul id="MenuBar1">'; while($row2=mysql_fetch_object($res2)){ $s2.='<li>'; $s2.='<a href="?'; if(isset($_GET['lang'])){ $s2.='lang='.$_GET['lang'].'&'; } $s2.='pg=sitemap&cat='.$row2->url.'&mbid='.$row2->id.'">'; if($_GET['lang'] == 'ru'){ $s2.= $row2->desc_ru; } elseif($_GET['lang'] == 'en'){ $s2.= $row2->desc_en; } else { $s2.= $row2->desc_lv; } $s2.='</a>'; $s2.=sitemap2($row2->id); $s2.='</li>'; } $s2.='</ul>'; $s2md.= str_replace(' class=""', '', $s2); return $s2md; } echo sitemap2(0); Link to comment Share on other sites More sharing options...
blackhalt Posted June 17, 2012 Report Share Posted June 17, 2012 Īsti laikam kaut ko nesaprotu, bet var taču vienkārši: echo '<ul id="MenuBar1">'; ... te viskautkas notiek. echo '</ul>'; Link to comment Share on other sites More sharing options...
404 Posted June 17, 2012 Report Share Posted June 17, 2012 Padod to id kā papildus parametru rekursijai tikai pirmo reizi: $ul_id = ' id="MenuBar1"'; function sitemap2($pid2, $ul_id) Link to comment Share on other sites More sharing options...
Cibiņš Posted June 17, 2012 Author Report Share Posted June 17, 2012 (edited) Īsti laikam kaut ko nesaprotu, bet var taču vienkārši: echo '<ul id="MenuBar1">'; ... te viskautkas notiek. echo '</ul>'; Nederēs, jo tad būs <ul id="MenuBar1"> <ul id="MenuBar1"> ........... </ul> </ul> Ņem vērā ka ieraksti nāk no datubāzes un lai tos sazarotu bez rekursijas neiztikt. 404 jau izmēģināju Tavu variantu iepriekš pirms sāku rakstit savu bēdu šeit, izvada erroru ka Missing argument 2 for sitemap2(), called ......, lai gan function sitemap2($pid2, $ul_id) izmēģināju arī kā function sitemap2($pid2, ' id="MenuBar1"') Pašlaik pēc Tava varianta ir šāds. $ul_id = ' id="MenuBar1"'; function sitemap2($pid2, $ul_id){ $sql2="SELECT * FROM pg_menu WHERE parent_id=".intval($pid2)." AND status = '1' ORDER BY position ASC;"; $res2=mysql_query($sql2); if(mysql_num_rows($res2)<1){ return ''; $axa=false; } $s2='<ul class="MenuBarVertical">'; while($row2=mysql_fetch_object($res2)){ $s2.='<li>'; $s2.='<a href="?'; if(isset($_GET['lang'])){ $s2.='lang='.$_GET['lang'].'&'; } $s2.='pg=netshop&cat='.$row2->url.'&mbid='.$row2->id.'">'; if($_GET['lang'] == 'ru'){ $s2.= $row2->desc_ru; } elseif($_GET['lang'] == 'en'){ $s2.= $row2->desc_en; } else { $s2.= $row2->desc_lv; } $s2.='</a>'; $s2.=sitemap2($row2->id); $s2.='</li>'; } $s2.='</ul>'; $s2md.= str_replace(' class=""', '', $s2); return $s2md; } echo sitemap2(0); Edited June 17, 2012 by Cibiņš Link to comment Share on other sites More sharing options...
404 Posted June 17, 2012 Report Share Posted June 17, 2012 Nu kļūda jau skaidri pasaka,ka otrajam parametram ir jābūt,ja reiz pirmo reizi ir definēts. Nekas tak neaizliedz nākamajā rekursijā padot tukšu stringu: $s2.=sitemap2($row2->id, ''); Link to comment Share on other sites More sharing options...
Cibiņš Posted June 17, 2012 Author Report Share Posted June 17, 2012 (edited) Paldies 404, sapratu, taga viss ir ok vienīgais nez kapēc tas id nav pievienojies pie pirmā jo kā skatos kodā, nekur nav atrodams tajā UL listē ka pie paša pirmā UL taga būtu pievienojies tas MenuBar identifikators! :/ $ul_id = ' id="MenuBar1"'; function sitemap2($pid2, $ul_id){ $sql2="SELECT * FROM pg_menu WHERE parent_id=".intval($pid2)." AND status = '1' ORDER BY position ASC;"; $res2=mysql_query($sql2); if(mysql_num_rows($res2)<1){ return ''; $axa=false; } $s2='<ul class="MenuBarVertical">'; while($row2=mysql_fetch_object($res2)){ $s2.='<li>'; $s2.='<a href="?'; if(isset($_GET['lang'])){ $s2.='lang='.$_GET['lang'].'&'; } $s2.='pg=netshop&cat='.$row2->url.'&mbid='.$row2->id.'">'; if($_GET['lang'] == 'ru'){ $s2.= $row2->desc_ru; } elseif($_GET['lang'] == 'en'){ $s2.= $row2->desc_en; } else { $s2.= $row2->desc_lv; } $s2.='</a>'; $s2.=sitemap2($row2->id, ''); $s2.='</li>'; } $s2.='</ul>'; $s2md.= str_replace(' class=""', '', $s2); return $s2md; } echo sitemap2(0,''); Edited June 17, 2012 by Cibiņš Link to comment Share on other sites More sharing options...
404 Posted June 17, 2012 Report Share Posted June 17, 2012 Un tagad pārskati visus $s2='<ul un atrodi kur tu šo $ul_id esi pielietojis :) Link to comment Share on other sites More sharing options...
Cibiņš Posted June 17, 2012 Author Report Share Posted June 17, 2012 (edited) Nu re cik smuki! Tieši tas kas man bija vajadzīgs! $ul_id = ' id="MenuBar1"'; function sitemap2($pid2, $ul_id){ $sql2="SELECT * FROM pg_menu WHERE parent_id=".intval($pid2)." AND status = '1' ORDER BY position ASC;"; $res2=mysql_query($sql2); if(mysql_num_rows($res2)<1){ return ''; } $s2='<ul class="MenuBarVertical"'.$ul_id.'>'; while($row2=mysql_fetch_object($res2)){ $s2.='<li>'; $s2.='<a href="?'; if(isset($_GET['lang'])){ $s2.='lang='.$_GET['lang'].'&'; } $s2.='pg=netshop&cat='.$row2->url.'&mbid='.$row2->id.'">'; if($_GET['lang'] == 'ru'){ $s2.= $row2->desc_ru; } elseif($_GET['lang'] == 'en'){ $s2.= $row2->desc_en; } else { $s2.= $row2->desc_lv; } $s2.='</a>'; $s2.=sitemap2($row2->id, ''); $s2.='</li>'; } $s2.='</ul>'; $s2md.= str_replace(' class=""', '', $s2); return $s2md; } echo sitemap2(0,$ul_id); Paldies Tev liels!! :)) Edited June 17, 2012 by Cibiņš Link to comment Share on other sites More sharing options...
Recommended Posts