Categories and Subcategories

6 posts by 2 authors in: Forums > CMS Builder
Last Post: April 16, 2012   (RSS)

By ikanizaj - April 13, 2012

Is it possible to set up category parents and children in a way that one list is generated depending on what is selected in the list of a parent category.

What I want is to have a structure like this:

category -> child category level 1 -> child category level 2 -> record

than I would like somehow to set adding of new record in a way that all parent categories are selectable:

category pulldown
child category level 1 pulldown
child category level 2 pulldown

Basicly what I want is to, when I select Category named "first", that in chlid category level 1 are displayed only options that have category "first" as parent category, and so on...
--
Igor Kani¾aj

Re: [ikanizaj] Categories and Subcategories

By Jason - April 13, 2012

Hi Igor,

What you can do is use the 'rootCategoryNum' option of getCategories() to do this.

For example, if you had a select field called "level1", when it was submitted, you can get all the children of the selected category like this:

EXAMPLE:

<?php
$level1Root = @$_REQUEST['level1'] ? intval($_REQUEST['level1']) : -1 ;

list($level2Records, $level2SelectedRecord) = getCategories(array(
'tableName' => 'categories',
'rootCategoryNum' => $level1Root,
));

?>


In this code, $level2Records would contain all the categories that are a child of the category value selected in level1

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [ikanizaj] Categories and Subcategories

By ikanizaj - April 14, 2012

Hi there Jason, just found your answer on what I was regarding to in another post.... [:)]

http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/Category_selection_populates_sub_categories_P91818/
--
Igor Kani¾aj

Re: [ikanizaj] Categories and Subcategories

By ikanizaj - April 14, 2012

SELECT num, title
FROM `<?php echo $TABLE_PREFIX ?>product_sub_category`
WHERE category = '<?php echo $ESCAPED_FILTER_VALUE;?>'

tought this will work, but it only works one level, and when I try to put another level, my pulldown list is displaying "loading" and nothing happens?
--
Igor Kani¾aj

Re: [ikanizaj] Categories and Subcategories

By Jason - April 16, 2012

Hi Igor,

I'm not sure I understand exactly what you're trying to do. Do you have 1 drop down with only top level categories and you want to use that to populate a second drop down with second level categories? The code your using doesn't look like it's referring to a category section at all. If you could provide some more clarification on the set up of the sections you are trying to use and what you need these fields to do, I should be able to put together an example for you.

Thanks,
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/