drisate Posted December 7, 2009 Share Posted December 7, 2009 Hey guys. I am creating a 10 level deep categorie systeme but i am completly lost in my logic and can't seem to figure this out... I have a table that looks like this: CREATE TABLE `page_categ_ass` ( `id` int(9) NOT NULL auto_increment, `s_categ_1` int(9) NOT NULL, `s_categ_2` int(9) NOT NULL, `s_categ_3` int(9) NOT NULL, `s_categ_4` int(9) NOT NULL, `s_categ_5` int(9) NOT NULL, `s_categ_6` int(9) NOT NULL, `s_categ_7` int(9) NOT NULL, `s_categ_8` int(9) NOT NULL, `s_categ_9` int(9) NOT NULL, `s_categ_10` int(9) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; And an other one like this: CREATE TABLE `page_categ` ( `id` int(9) NOT NULL auto_increment, `nom` varchar(250) NOT NULL, `type` int(9) NOT NULL, `place` int(1) NOT NULL, `ordre` int(9) NOT NULL, `cronique` int(9) NOT NULL, `mcat` varchar(9) NOT NULL, `nom_en` varchar(250) NOT NULL, `s_categ` int(9) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; What i am trying to do is create a catégorie in page_categ then associate it with the page_categ_ass table using the id of the association as the s_categ of page_categ. To do that i need to create a menu box with all the categories in order. I am trying to do something that looks like this: Name -Sub 1 -Sub 1 --Sub 2 ---Sub 3 ---Sub 3 ----Sub 4 -----Sub 5 ------Sub 6 ------Sub 6 ------Sub 6 ------Sub 6 -------Sub 7 [Ext] But i can't seem to figure out how ... This is the code i have so fare function arbre($col, $loop, $current, $now){ if ($loop==""){$loop="1";} if ($now==""){$now = @current(@mysql_fetch_assoc(@mysql_query("SELECT s_categ_1 FROM page_categ_ass order by id asc limit 1")));} $select = mysql_query("SELECT * FROM page_categ_ass where $col='$now' order by id asc") or die(mysql_error()); while ($page_ass = mysql_fetch_array($select)) { $i = 1; while($i < 10) { $espace .= "-"; $i++; } $b = 1; while($b < $loop) { $value .= $page_ass['s_categ_'.$loop]."-"; $b++; } $value = substr($value, 0, -1); echo '<option value="'.$value.'" '; if ($page_ass['s_categ_'.$loop]==$current){echo "SELECTED";} echo '>'.$espace.'</option>'; } $loop++; if ($loop<="10"){ arbre("s_categ_$loop", $loop, $current, $now); } } I am lost ... I have no idea how to do this. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/184275-i-am-loste-in-my-loop-logic/ Share on other sites More sharing options...
rajivgonsalves Posted December 7, 2009 Share Posted December 7, 2009 first of all your why do you have 10 fields for categories ? , your category table should have a parent_id which points to the parent category ? Link to comment https://forums.phpfreaks.com/topic/184275-i-am-loste-in-my-loop-logic/#findComment-972901 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.