Jump to content

Nested SubCategory


v1n_vampire

Recommended Posts

Hello all, I want to make a select box containing category list ordered by category name, where each category may have a parent category or endless child category. I found that the case is very similar to forum and subforum, but I don't have left_id or right_id in my table.

 

Database table:

  category_id 

  parent_id 

  category_name 

  description 

  1

  0

  name A

  this category doesn't have parent category

  2

  0

  name B

  this category doesn't have parent category

  3

  2

  name C

  this category is under category 2

  4

  1

  name D

  this category is under category 1

  5

  3

  name F

  this category is under category 3

  6

  3

  name E

  this category is under category 3

 

Wanted result:

• Name A

•• Name D

• Name B

•• Name C

••• Name E

••• Name F

 

Can anyone help me, please? Thank you~

Link to comment
Share on other sites

you would need some serious coding to get that done.  Your table isn't really set up properly for that kind of output.  a single level + single sublevel isn't a problem, but to recusevly build a full depth tree from just a single parent folder listing isn't going to be fun.  You may be lucky and one of the other guys here has some code to hand that could work, but if not that's a big ask.

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.