Jump to content

I am loste in my loop logic :-(


drisate

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.