Displaying value & label for related table list items on Category Menu page

6 posts by 3 authors in: Forums > CMS Builder
Last Post: December 17, 2025   (RSS)

Hi, All.

I need to display both $value (numeric) and $label from the related businesses list field on the same line. Right now, I can only display either $value or $label. How can I output both together?

In the 'activity' Category Menu table, the 'related_businesses' list field is set up as:
- Get options from database (advanced)
- Section Tablename: business_directory
- Field for option values: num
- Field for option labels: business_name

Desired output:
If thhe record num in the related 'business_directory' table is 23, the HTML would be:

<li><a href="directory.php#biz-23">Business ABC</a></li>
<li><a href="directory.php#biz-45">Business XYZ</a></li>

Page setup:

  // load records from 'activity'
  list($activityRecords, $selectedActivity) = getCategories(array(
    'tableName'            => 'activity', //
    'categoryFormat'       => 'showall', 
    'defaultCategory'      => '1', 

    // advanced options (you can safely ignore these)
    'rootCategoryNum'      => '',
    'ulAttributes'         => '',
    'selectedCategoryNum'  => '',
    'ulAttributesCallback' => '',
    'liAttributesCallback' => '',
    'loadCreatedBy'        => false,
    'loadUploads'          => true,
    'ignoreHidden'         => false,
    'debugSql'             => false,
  ));

Current code resulting in - undefined variable "$value":

<?php foreach ($activityRecords as $record): ?>

<h2><?php echo htmlencode($record['name']) ?></h2>

<h3>Related Businesses</h3>
<ul>
<?php foreach ($record['business_directory_num:labels'] as $label): ?>
<li><a href="/business/directory/index.php#biz-<?php echo $value; ?>"><?php echo $label; ?></a></li>
<?php endforeach; ?>
</ul>
      
<?php endforeach ?>

---------------------------------

Can anyone offer a suggestion?

Deborah

Hello, Christine.

I was unaware of the "two parallel arrays possibility". That works perfectly!

Thanks so much for your help.
Deborah

By Dave - December 17, 2025

And I'll just add that you can always use our convenience showme() function to see what fields are available:

<?php showme($record); ?>
Dave Edis - Senior Developer



interactivetools.com

Hi Dave — thanks for the reminder about showme().

It’s a really handy tool, and I did use it here, but I wasn’t sure how to display both the values and the labels in this related use case.

Christine helped point me in the right direction, and I’ve now saved a working snippet in my CMSB library for future reference.

Appreciate the great support!

~ Deborah

By Dave - December 17, 2025

Hi Deborah, 

Oh, of course.  Sorry, I scanned that post a bit too quickly.  

Glad it's worked now! :-)

Dave Edis - Senior Developer



interactivetools.com