Display Sub-categories in a Simple List

6 posts by 2 authors in: Forums > CMS Builder
Last Post: November 30, 2010   (RSS)

Re: [cjpritchard] Display Sub-categories in a Simple List

By Jason - November 30, 2010

Hi Chris,

What field do you have in participants that associates them with a category? This is the field you need to check when outputting your records,

I'll give you an example of how it should work. In this example, I'll assume you have a field in participants called 'category' that's a drop down menu. I'll also assume that in its value field, you're storing the num field from the category section.

If this is true, here is how we can output these records:

<?php foreach ($categoriesRecords as $categoryRecord): ?>
<h2><?php echo $categoryRecord['name'] ?></h2>
<ul>

<?php foreach ($participantsRecords as $record): ?>
<?php if($record['category']==$categoryRecord['num']):?>

<li><?php if ($record['url']): ?><a href='http://<?php endif ?>
<?php echo $record['url'] ?><?php if ($record['url']): ?>' target='_blank'><?php endif ?><?php echo $record['title'] ?>
<?php if ($record['url']): ?></a><?php endif ?>
<span class="contact-info"><?php echo $record['phone_number'] ?></li>

<?php endif ?>
<?php endforeach ?>

</ul>

<?php endforeach ?>


So in this code, as it loops through the participants records, it will only output records where the category field is equal to the num of the category record currently being outputted.

Give this a try and let me know if you run into any issues.

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: [Jason] Display Sub-categories in a Simple List

Hi Jason,

Thanks very much for your help. Yes, I have a category field in the participants table and it's using the num field from the category section.

Here's the page now: http://www.tucg.ca/participants2.html

Thanks again,
Chris

Re: [Jason] Display Sub-categories in a Simple List

Hi again Jason,

At the top of this page (http://www.tucg.ca/participants2.html) I have a note "35 PARTICIPANTS AND GROWING!" How can I make this number 35 dynamic, so it reads the number of name fields from the participants table?

Thanks,
Chris

Re: [cjpritchard] Display Sub-categories in a Simple List

By Jason - November 30, 2010

Hi Chris,

Replace the number 35 with this:
<?php echo count($participantsRecords);?>

This will output the number of records stored in $participantsRecords.

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: [Jason] Display Sub-categories in a Simple List

Perfect, thanks very much.

Chris