display list of items beneath selected category

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 20, 2013   (RSS)

By Deborah - June 17, 2013

I have a 'resources' list editor that allows category selection from a separate 'resource_categories' table. The site owner needs to be able to update the categories table, so I can't hard-code the viewer categories onto the page.

Desired outcome is a list of categories with resources displayed beneath them:

Category 1 Resource A details Resource B details Resource C details
Category 2 Resource A details Resource B details Resource C details
(etc)

My CMSB tables are set up as:

Table 1) 'resource_categories' with 'title' text field

Table 2) 'resources' contains a pulldown list w/options from 'resource_categories' table option values = num option labels = title

Is this outrageously simple and I just haven't found the right forum search?

A BIG thanks in advance.

~ Deborah

By Deborah - June 19, 2013

Jason,

I attempted the code in your post, but got an error I couldn't get past (possibly something I did wrong). However, your clue led me to an older post of yours (http://www.interactivetools.com/forum/forum-posts.php?postNum=2217490#post2217490) and between the two, I was able to arrive at what I needed.

My resulting code (field names different than original post): 

<?php $museumsByCategory = array_groupBy($museumsRecords, 'category', true); ?>
<?php foreach (getListOptions('museums', 'category') as $value => $label): ?>
<?php $museums = @$museumsByCategory[$value]; ?>

<?php echo $label;?> 
 
<?php foreach ($museums as $museum): ?>
<?php echo htmlencode($museum['title']) ?>
<?php endforeach ?> 
 
<?php endforeach ?>

 You really got me out of a spot! Thank you so much!

~ Deborah

By Jason - June 20, 2013

Hi Deborah,

Excellent!  Glad to hear everything is working for you now.  Please let me know if you have any other questions.

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/