hamza Posted March 16, 2010 Share Posted March 16, 2010 i have a function which is recursively creating list menu i only want to include classes , span tag kindly see the output schema is attached mysql_connect('localhost','root','root');mysql_select_db('sre'); global $menu_array; //running query $result = mysql_query("SELECT * FROM `tblcatagory`"); //fetch rows to show like tree while ( $row = mysql_fetch_assoc($result) ) { $menu_array[$row['cat_id']] = array('Categoryid'=> $row['cat_id'],'name' => $row['cat_name'],'parent' => $row['parent']); } //recursive function that prints categories as a nested html unorderd list function generate_menu($parent) { $has_childs = false; //this prevents printing 'ul' if we don't have subcategories for this category //make array global global $menu_array; //use global array variable instead of a local variable to lower stack memory requierment foreach($menu_array as $key => $value) { if ($value['parent'] == $parent) { //if this is the first child print '<ul>' if ($has_childs === false) { //don't print '<ul>' multiple times $has_childs = true; echo '<ul id="red" class="treevi ew-red treeview">'; } echo '<li> <span> ' . $value['name'].'</span>'; generate_menu($key); //call function again to generate nested list for subcategories belonging to this category echo '</li>'; } } if ($has_childs === true) echo '</ul>';} echo generate_menu(0); i need output like this .......... <UL id="red" class="treeview-red treeview"> <LI><A href="http://www.aeesolar.com/catalog/index.html" id="ovwLink">Overview</A></LI> <LI class="expandable"><DIV class="hitarea expandable-hitarea"></DIV><SPAN>Pre-Configured Systems</SPAN> <UL style="display: none; "> <LI><A href="./AEE Solar grid-tie PV power systems, grid-tie solar power systems_files/AEE Solar grid-tie PV power systems, grid-tie solar power systems.htm" class="selected">Grid-tie</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_PC_GTBB.htm">Grid-tie with battery backup</A></LI> <LI class="last"><A href="http://www.aeesolar.com/catalog/products/H_ASW_PC_RP.htm">Remote power</A></LI> </UL> </LI> <LI class="expandable"><DIV class="hitarea expandable-hitarea"></DIV><SPAN class="">Solar Modules</SPAN> <UL style="display: none; "> <LI class="expandable"><DIV class="hitarea expandable-hitarea "></DIV><SPAN>PV modules</SPAN> <UL style="display: none; "> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_EGS.htm">Evegreen</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_REC.htm">REC</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_MIT.htm">Mitsubishi</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_SWD.htm">SolarWorld</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_SCT.htm">SCHOTT Solar</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_KYO.htm">Kyocera</A></LI> <LI class="last"><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PVM_AEE.htm">AEE Solar</A></LI> </UL> </LI> <LI class="expandable lastExpandable"><DIV class="hitarea expandable-hitarea lastExpandable-hitarea "></DIV><SPAN>Portable PV modules</SPAN> <UL style="display: none; "> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PPVM_GSE.htm">Global Solar</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PPVM_PFM_RU.htm">PowerFilm roll-up</A></LI> <LI class="last"><A href="http://www.aeesolar.com/catalog/products/H_ASW_SM_PPVM_PFM_UF.htm">PowerFilm ultra-flexible</A></LI> </UL> </LI> </UL> </LI> <LI class="collapsable"><DIV class="hitarea collapsable-hitarea"></DIV><SPAN class="">Mounting Structures</SPAN> <UL style="display: block; "> <LI class="expandable"><DIV class="hitarea expandable-hitarea "></DIV><SPAN>SnapNrack</SPAN> <UL style="display: none; "> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_SNR_UK.htm">Universal kits</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_SNR_SR.htm">Standard rail sets</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_SNR_RA.htm">Roof attachment pieces</A></LI> <LI class="last"><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_SNR_GM.htm">Ground mount</A></LI> </UL> </LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_QMT.htm">Quick Mount PV - waterproof flashing</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_CRT.htm">CreoTecc tile - roof hooks</A></LI> <LI class="expandable"><DIV class="hitarea expandable-hitarea "></DIV><SPAN>Unirac</SPAN> <UL style="display: none; "> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_CMS.htm">CLICKSYS Mounting system</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_2R.htm">2-rail kits</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_4R.htm">4-rail kits</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_RB.htm">Bulk rail bundles</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_LF.htm">L-feet</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_SBP.htm">Splice bars and plates</A></LI> <LI class="expandable"><DIV class="hitarea expandable-hitarea "></DIV><SPAN>Top mounting clamp sets</SPAN> <UL style="display: none; "> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_CS_A.htm">Clear anodized</A></LI> <LI><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_CS_B.htm">Dark bronze</A></LI> <LI class="last"><A href="http://www.aeesolar.com/catalog/products/H_ASW_MS_UNR_CS_LFM.htm">Lipped frame model</A></LI> </UL> </LI> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/195408-add-anchors-and-spans/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.