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

3 posts by 2 authors in: Forums > CMS Builder
Last Post: 5 hours ago   (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