0

First question on stackoverflow. I used this A more dynamic way of nesting multi-level categories for creating multilevel category table for my assignment.

I have childof field in category table for managing parent-child relationship. I am clear about fetching these categories based on childof. The root categories will have "childof = 0".

While adding a new category , I will represent a choose parent drop down of all categories in the form and user will choose one parent for this new category child (which is to be added).

I am confused about updating the categories : -

While updating a category , I am having two problems. a) I can not use current choosen category in the choose parent drop down as this will assign parent to itself. I mean same id can not have same childof id ?? what do you think ?

b) What about editing root categories ?? Editing their parent and moving them to other sub levels can cause problems ??

Any other way of doing this is most welcome.

please help

Community
  • 1
  • 1
phpgeek
  • 47
  • 6
  • 13

2 Answers2

0

There are lot of ways to solve this, there is a discussion already answered on this please refer this

Community
  • 1
  • 1
Sandeep Manne
  • 6,030
  • 5
  • 39
  • 55
  • HI Sandeep , thanks for replying but I thing this is not the one I am looking for. This is all about fetching the child categories and all. I want to know about adding/updating each catetgory and their related parents. thanks – phpgeek Apr 06 '12 at 06:32
0

Welcome to StackOverflow; I hope you've read the faqs

In answer to your questions:

  • (a) Yes, you can just restrict the "select parent" drop-down to list all categories except the current one. One way to do this is by retrieving the correct categories, i.e.

    SELECT category_id,category_name FROM categories WHERE category_id != $thisCategoryId

Or you can do it in the php code by checking each value when you loop through them.

  • (b) Yes it would cause you problems if you move a category to be a sub-category of one of its own sub-categories so you will need to check that as well
Community
  • 1
  • 1
liquorvicar
  • 6,081
  • 1
  • 16
  • 21
  • Thanks Liquorvicar. :) ... in case (b) please suggest something – phpgeek Apr 06 '12 at 07:54
  • @vikassharma The way we solved this problem in our app was to load the whole tree in PHP and remove the whole branch with the current id as the root from the possible options. – liquorvicar Apr 06 '12 at 07:56
  • Ok thanks Liquorvicar. thanks for your help. I was also supposing something like that after your reply... :):).. – phpgeek Apr 06 '12 at 08:35
  • @vikassharma Have a go and if you get stuck come back to SO and ask another question! – liquorvicar Apr 06 '12 at 08:40