Populate subcategories from parent categories

6 posts by 2 authors in: Forums > CMS Builder
Last Post: September 23, 2014   (RSS)

By Jesus - September 17, 2014

Ok...

I created 3 tables.

Families

Categories

Products

Now, I can select the Family with no problem while creating a new product but now, I still need to display Categories related to the family I selected from my Family list

Hi Jesus,

I think I understand what you're trying to achieve. So when a user selects a family from the first drop down, the second drown will only display categories that are linked to that family?

I think you need to use an advanced MySQL drop down, and then use a ESCAPED_FILTER_VALUE to filter the drop down. Here are a couple of posts that go over how to implement the system:

http://www.interactivetools.com/forum/forum-posts.php?postNum=2230106#post2230106

http://www.interactivetools.com/forum/forum-posts.php?postNum=2232494#post2232494

Let me know if you have any questions on how to implement this feature.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Jesus - September 19, 2014

AWESOME Greg!!!

Both threads helped me!!

Thank you so much!

Jesus

By Jesus - September 22, 2014

Hi Greg,

I made this possible but now, I've another question. I did it previously on other CMSBuilder project but on this one, its the 1st time I'm using this ESCAPED_FILTER_VALUE method.

I'm creating a filer by category on my front end page, so I can display all products for all categories or just a category specific products. I'm assuming that the category value remains on the database once I save the record.

Here's the code I'm using:

<a href="#" class="btn btn-default" data-filter="*">Todos</a>

<?php foreach (getListOptions("productos", "categoria") as $value => $label):?>
   <a href="#" class="btn btn-default" data-filter=".<?php echo $value;?>"><span class="hidden-xs"><?php echo $label;?></span></a>
<?php endforeach ?>

I'm not getting any category (categoria) value here. Am I missing something?

Thanks for the head-ups,

Jesus

Hi Jesus,

I suspect the issue is that you don't have a value set for ESCAPED_FILTER_VALUE on the front end of your site, and so no values are being returned. You could update your MySQL string for your list field so that if no value is set for ESCAPED_FILTER_VALUE, all of the records are returned:

<?php if(@$ESCAPED_FILTER_VALUE): ?> 
 Current MySQL call here
<?php else: ?>
 MySQL call to return all data instead.
<?php endif; ?>

Another way to do this would be to use getRecords to return all of your categories on the front end page, and cycle through those instead:

<?php

  // load records from 'members'
  list($categorias, $categoriaMeta) = getRecords(array(
    'tableName'   => 'categoria',
    'loadUploads' => true,
    'allowSearch' => false,
  ));


?>
<a href="#" class="btn btn-default" data-filter="*">Todos</a>

<?php foreach ($categorias as $categoria):?>
   <a href="#" class="btn btn-default" data-filter=".<?php echo $categoria['num'];?>"><span class="hidden-xs"><?php echo $categoria['title'];?></span></a>
<?php endforeach ?> 

So the above code will return all categories from the categoria table, then cycle through them and display the appropriate num and title. This is just example code, so you'll probably have to make a few changes to get it working with your system.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com