hamza Posted March 17, 2010 Share Posted March 17, 2010 menu need to be compleat need check for ending ul tag and and proper nesting require.plz have a look plz compleat it i am bothering for long time <?php // $current_cat_id: the current category id number // $count: just a counter, call it as 0 in your function call and forget about it /* GET THE DROP DOWN LIST OF CATEGORIES */ function get_cat_selectlist($current_cat_id, $count, $ul_tag_started) { static $option_results; // if there is no current category id set, start off at the top level (zero) if (!isset($current_cat_id)) { $current_cat_id =0; } // increment the counter by 1 $count = $count+1; mysql_connect('localhost','root','root'); mysql_select_db('sre'); // query the database for the sub-categories of whatever the parent category is $sql = 'SELECT cat_id, parent ,cat_name from `tblcatagory1` where parent = '.$current_cat_id; // $sql .= 'order by parent asc '; $get_options = mysql_query($sql); $num_options = mysql_num_rows($get_options); // our category is apparently valid, so go ahead €¦ if ($num_options > 0) { while (list($cat_id, $parent, $cat_name) = mysql_fetch_row($get_options)) { // ON ROOT 0 JUST ADD TAG <li> if ($current_cat_id==0 ) { $option_results[$cat_id] = '<li>'. $cat_name.'</li>'; // now call the function again, to recurse through the child categories get_cat_selectlist($cat_id, $count ,'no'); } //same parent then JUST ADD TAG <ul> <li> if ( $current_cat_id === $parent ) { if ($ul_tag_started=='no') { $option_results[$cat_id] = '<ul> <li>'. $cat_name .'</li>'; // now call the function again, to recurse through the child categories get_cat_selectlist($cat_id, $count, 'yes'); }else if ($ul_tag_started=='yes') { //if ul tag started $option_results[$cat_id] = '<li>'. $cat_name.'_'.$cat_id.'</li>'; //now call the function again, to recurse through the child categories get_cat_selectlist($cat_id, $count , ''); } } }//while fetching }//if greter the zero return $option_results; }//function //calling function $get_options = get_cat_selectlist(0, 0,'no'); //print_r($get_options); echo '<ul>'; foreach ($get_options as $key => $value) { echo $value; } echo $options; echo '</ul>'; /* echo '<select name="cat_id">'; echo '<option value="">-- Select -- </option>'; $get_options = get_cat_selectlist(0, 0); if (count($get_options) > 0){ $categories = $_POST['cat_id']; foreach ($get_options as $key => $value) { $options .="<option value=\"$key\""; // show the selected items as selected in the listbox if ($_POST['cat_id'] == "$key") { $options .=" selected=\"selected\""; } $options .=">$value</option>\n"; } } echo $options; echo '</select>'; */ ?> <!-- /* MySQL Data Transfer Source Host: localhost Source Database: sre Target Host: localhost Target Database: sre Date: 3/17/2010 9:59:50 AM */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for tblcatagory1 -- ---------------------------- CREATE TABLE `tblcatagory1` ( `cat_id` int(10) NOT NULL auto_increment, `parent` int(10) default NULL, `cat_name` varchar(255) default NULL, `cat_description` varchar(255) default NULL, `image` varchar(255) default NULL, `date_updated` datetime default NULL, PRIMARY KEY (`cat_id`) ) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `tblcatagory1` VALUES ('1', '0', 'Sports', 'sports description', null, '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('2', '1', 'hockey', 'hockey decription', null, '2004-09-04 00:30:35'); INSERT INTO `tblcatagory1` VALUES ('3', '1', 'football', 'football description', null, null); INSERT INTO `tblcatagory1` VALUES ('4', '0', 'Books', 'sdfasdf', null, '2004-09-17 00:30:38'); INSERT INTO `tblcatagory1` VALUES ('5', '4', 'Classics', 'sdfasdf', null, '2004-09-24 00:30:40'); INSERT INTO `tblcatagory1` VALUES ('6', '4', 'Historical', 'sadfsadfwe', null, '2004-09-30 00:30:32'); INSERT INTO `tblcatagory1` VALUES ('7', '4', 'Horror', 'fefwefwefwef', null, '2004-09-17 00:35:35'); INSERT INTO `tblcatagory1` VALUES ('8', '4', 'Mystery, Thriller', '<p>fwefwefv we</p>', null, '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('9', '4', 'Religious, Inspirational', 'fv wefwefwefv we', null, '2004-09-10 00:30:29'); INSERT INTO `tblcatagory1` VALUES ('10', '7', 'Detective', 'fwefcv we fwefwef ', null, '2004-09-03 00:30:27'); INSERT INTO `tblcatagory1` VALUES ('11', '7', 'Suspense', 'fwecf ew we wefwe e', null, '2004-09-03 00:30:46'); INSERT INTO `tblcatagory1` VALUES ('12', '2', 'hocky1', 'jjj', '', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('13', '2', 'hocky2', 'a', '', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('14', '2', 'hocky3', 'a', '', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('15', '2', 'hocky4', '<p> ssssss</p>', '1096398814.jpg', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('16', '6', 'his1 book', '<p> sssssssssssssssssssssssssssss1313131313</p>', '1096398862.jpg', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('17', '6', 'his2 book', '<p> sssssssssssssssssssssssssssss1313131313</p>', '', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('18', '3', 'sdfsfsdffsdfs', '<h1> sdfsafsf</h1>', '', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('19', '8', 'MT1', '<p> aaaaaaaaaaaaaaaaaaaaaaaaa</p>', '', '2004-09-29 00:00:00'); INSERT INTO `tblcatagory1` VALUES ('20', '2', 'hockey team', '<p> aaaaaaaaaaaaaaaaaaa</p>', '1096400901.jpg', '2004-09-29 00:00:00'); --> Link to comment https://forums.phpfreaks.com/topic/195595-menu-need-to-be-compleat-with-little-nesting-require/ Share on other sites More sharing options...
sasa Posted March 17, 2010 Share Posted March 17, 2010 try <?php function get_cat_selectlist($current_cat_id = 0) { mysql_connect('localhost','root','root'); mysql_select_db('sre'); $sql = 'SELECT cat_id, parent ,cat_name from `tblcatagory1` where parent = '.$current_cat_id; $get_options = mysql_query($sql); $num_options = mysql_num_rows($get_options); $out = ''; if ($num_options > 0) { // start ul tag $out = "<ul>\n"; while (list($cat_id, $parent, $cat_name) = mysql_fetch_row($get_options)) { $out .= '<li>'. $cat_name.'</li>'."\n"; $out .= get_cat_selectlist($cat_id); } $out .= "</ul>\n"; }//if greter the zero return $out; }//function echo get_cat_selectlist(); ?> Link to comment https://forums.phpfreaks.com/topic/195595-menu-need-to-be-compleat-with-little-nesting-require/#findComment-1027785 Share on other sites More sharing options...
hamza Posted March 17, 2010 Author Share Posted March 17, 2010 thanks for your attantion but i am not will to have this way.can you add flexblility of adding any tag with li and ul tags . like with ul span div and same as li too. something like =========== <LI>Solar Modules <UL> <LI>PV modules <UL> <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>Portable PV modules <UL> <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> Link to comment https://forums.phpfreaks.com/topic/195595-menu-need-to-be-compleat-with-little-nesting-require/#findComment-1027802 Share on other sites More sharing options...
sasa Posted March 17, 2010 Share Posted March 17, 2010 for class='last' just count items i while loop and compare it with num_options Link to comment https://forums.phpfreaks.com/topic/195595-menu-need-to-be-compleat-with-little-nesting-require/#findComment-1027816 Share on other sites More sharing options...
hamza Posted March 18, 2010 Author Share Posted March 18, 2010 i all most there but a very little check is require like sports and hockey are roots category i need span in both and subcateory shoud be in anchor # Sports * hockey o hocky1 o hocky2 o hocky3 o hocky4 o hockey team <?php function get_cat_selectlist($current_cat_id = 0) { mysql_connect('localhost','root','root'); mysql_select_db('sre'); $sql = 'SELECT cat_id, parent ,cat_name from `tblcatagory1` where parent = '.$current_cat_id; $get_options = mysql_query($sql); $num_options = mysql_num_rows($get_options); echo '<pre >'; echo $sql.'--total---'.$num_options; $out = ''; if ($num_options > 0) { // start ul tag $i=1; $out = "<ul>\n"; while (list($cat_id, $parent, $cat_name) = mysql_fetch_row($get_options)) { if( $i!=$num_options) { $out .= '<li><span>'. $cat_name.'<span> </li>'."\n"; }else { $out .= '<li><a href="www.google.com">'. $cat_name.'</a></li>'."\n"; } $out .= get_cat_selectlist($cat_id); $i++; } $out .= "</ul>\n"; }//if greter the zero return $out; }//function echo get_cat_selectlist(); ?> Link to comment https://forums.phpfreaks.com/topic/195595-menu-need-to-be-compleat-with-little-nesting-require/#findComment-1027960 Share on other sites More sharing options...
trq Posted March 18, 2010 Share Posted March 18, 2010 Were not here to write code for people. Sheesh. Link to comment https://forums.phpfreaks.com/topic/195595-menu-need-to-be-compleat-with-little-nesting-require/#findComment-1027967 Share on other sites More sharing options...
Recommended Posts