customizing Dropdownlist

Hello Everyone

I have found myself stuck trying to display my drop down list the way I want it. Basically I have 3 fields in one Table named Category…

ParentID

ID

Name

All fields are mandatory, my code atm is as so





					<?php echo $form->dropDownList($model,'ParentID', CHtml::listData(ECCategory::model()->findAll(),   'ID', 'Name','ParentID' ));?>




What this does is list all the Category names under a ParentID. So for example I have

ID 9. 1. 2. 3. 4. 5.

Assuming the following Name belong the following ID’s and inside the brackets is the ParentID

Name 9.Electronics(), 1.Accessories(9), 2.Video Players(9), 3.Audio Players(9), 4.Cameras(9), 5.Headphones(1)

The Output I get now is

0

Electronics

9

Accessories

Video Players

Audio Players

Cameras

1

Headphones

What I intend to get is

Electronic

-Accessories

Headphones

-Video Players

-Audio Players

-Cameras

I’m a little bit stuck here, I was thinking I can include a condition but how do I include a condition in a dropdownlist??

Hope this makes sense, I need a direction tbh

Regards

I think this extension should be the solution.

http://www.yiiframework.com/extension/nestedsetbehavior

Hwy Softark

Thanks for the reply, I checked the link out but it seems for someone starting a new database. I have over 1000 products, I just don’t understand how I can implement the extension with my DB. I can’t define which one is root and which is a Node one by one (not feasible), not sure of my DB structure can work with it. I was really looking for a different solution (if there’s one) such as how do I place conditions in a dropdown list…

Thanks again

Best Regards

Does anyone have another solution to this? I’m still attempting my own way but having no luck.

Stuck here pretty badly

Thanks