Jump to content
php.lv forumi

Submenu rekursijas funkcija - spec. klases ievietošana pie <a href


Cibiņš

Recommended Posts

Īsti nesaprotu..man ir rekursijas funkcija kas veido vairāklīmeņa izvēlnes.

 

 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 '';
}
$s2='<ul id="MenuBar1" class="MenuBarVertical">';
while($row2=mysql_fetch_object($res2)){
 	$s2.='<li>';
     $s2.='<a href="#">';
 	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>';
return $s2;      
 }
?>

 

kas atgriež

 

<pre id="line1"><ul id="MenuBar1" class="MenuBarVertical">  <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 1</a>    <ul></pre><pre id="line21">      <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 1.1</a></li>      <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 1.2</a></li>      <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 1.3</a></li>    </ul>  </li>  <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 2</a></li>  <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 3</a>    <ul>      <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 3.1</a>        <ul>          <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 3.1.1</a></li>          <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 3.1.2</a></li>        </ul>      </li></pre><pre id="line28">      <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 3.2</a></li>      <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 3.3</a></li>    </ul>  </li>  <li><a href="[url="view-source:http://localhost:81/dropdown/#"]#[/url]">Item 4</a></li></ul></pre>

 

Kā panākt lai rekursija pieliek klasi

class="MenuBarItemSubmenu"

pie pirmā hrefa, kam seko apakšlīmenis?

 

Tipa lai

<ul id="MenuBar1" class="MenuBarVertical">
 <li><a href="#">Item 1</a>
<ul>
 	<li><a href="#">Item 1.1</a></li>
 	<li><a href="#">Item 1.2</a></li>
 	<li><a href="#">Item 1.3</a></li>
</ul>
 </li>
 <li><a href="#">Item 2</a></li>
 <li><a href="#">Item 3</a>
<ul>
 	<li><a href="#">Item 3.1</a></li>
 	<li><a href="#">Item 3.2</a>
   	<ul>
     	<li><a href="#">Item 3.2.1</a></li>
     	<li><a href="#">Item 3.2.2</a></li>
     	<li><a href="#">Item 3.2.3</a></li>
   	</ul>
 	</li>
 	<li><a href="#">Item 3.3</a></li>
</ul>
 </li>
 <li><a href="#">Item 4</a></li>
</ul>

 

nostrādā kā

 

<ul id="MenuBar1" class="MenuBarVertical">
 <li><a class="MenuBarItemSubmenu" href="#">Item 1</a>
<ul>
 	<li><a href="#">Item 1.1</a></li>
 	<li><a href="#">Item 1.2</a></li>
 	<li><a href="#">Item 1.3</a></li>
</ul>
 </li>
 <li><a href="#">Item 2</a></li>
 <li><a class="MenuBarItemSubmenu" href="#">Item 3</a>
<ul>
 	<li><a href="#">Item 3.1</a></li>
 	<li><a class="MenuBarItemSubmenu" href="#">Item 3.2</a>
   	<ul>
     	<li><a href="#">Item 3.2.1</a></li>
     	<li><a href="#">Item 3.2.2</a></li>
     	<li><a href="#">Item 3.2.3</a></li>
   	</ul>
 	</li>
 	<li><a href="#">Item 3.3</a></li>
</ul>
 </li>
 <li><a href="#">Item 4</a></li>
</ul>

Edited by Cibiņš
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...