Display images from a "category" menu type, used as a list pulldown in a "multi" menu type and displayed on a list page

3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 16, 2015   (RSS)

By Zicky - November 12, 2015

I like long descriptive titles on the forum - helps me find solutions faster, hence the long title.

On to the issue I have.

I have a "category" menu type (zoning_rezoning_status) which has a:
Name field
Upload field (for uploading an icon that represents the name of the category recored created. For example: if the category record name was "Dog" then I'd upload an icon of a dog.

Next I have a "multi" menu type (zoning_rezoning) which has a "list" field type called (status) set to "pulldown" with the options selected below:
Get options from database (advanced)
Section Tablename (set to) zoning_rezoning_status
Use this field for option values (set to) num
Use this field for option labels (set to) name

So I am creating records in the "multi" menu type (zoning_rezoning) and selecting from the pulldown called (status) to associate a "category" of the (zoning_rezoning_status) with the record of the "multi" menu type (zoning_rezoning).

I need to display the singular uploaded "icon" of the (zoning_rezoning_status) record associated with the record for the (zoning_rezoning) record on the "multi" List Page, but presently all icons of the (zoning_rezoning_status) are appearing for each "multi" list record on the List Page. Anyone have any suggestion on what I need to do to get this to work, so that the appropriate icon is displayed with the associated with the multi record created?

Here's my code:

<?php
if (@$_REQUEST['searchResultsPerPage'] AND is_numeric(@$_REQUEST['searchResultsPerPage'])){
  $perPage = $_REQUEST['searchResultsPerPage'];
}
else{
  $perPage = '6';
}
  
    // load records from 'zoning_rezoning'
  list($zoning_rezoningRecords, $zoning_rezoningMetaData) = getRecords(array(
    'tableName'   => 'zoning_rezoning',
'perPage'     => @$perPage ? $perPage : '6',
'loadUploads' => true,
'allowSearch' => true,
    'orderBy'     => 'date DESC',
  ));
  
    // load records from 'zoning_rezoning_status'
  list($zoning_rezoning_statusRecords, $zoning_rezoning_statusMetaData) = getRecords(array(
    'tableName'   => 'zoning_rezoning_status',
    'where'       => "name LIKE '%".$zoning_rezoningRecords['status:label']."%' ",
    'loadUploads' => true,
    'allowSearch' => false,
  ));


?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Zoning Multi</title>
</head>

<body>
<?php foreach ($zoning_rezoningRecords as $record): ?>
<?php echo htmlencode($record['title']) ?>
<?php echo htmlencode($record['summary']) ?>

<?php if ($record['status']): ?>
<div>
<h6><?php echo $record['status:label'] ?></h6>

<?php foreach ($zoning_rezoning_statusRecords as $statusicon): ?>
      <?php foreach ($statusicon['status_icon'] as $index => $uploadedicon): ?>
      <img src="<?php echo htmlencode($uploadedicon['thumbUrlPath2']) ?>" width="<?php echo $uploadedicon['thumbWidth2'] ?>" height="<?php echo $uploadedicon['thumbHeight2'] ?>" alt="<?php echo $record['status:label'] ?>" />
      <?php endforeach ?>
<?php endforeach; ?>
<div class="clear-both"></div>
</div>
<?php endif; ?>

<?php endforeach ?>
</body>
</html>

Thanks Zicky

By Daryl - November 16, 2015

Hi Zicky,

On your foreach block for $zoning_rezoning_statusRecords, you can skip displaying the icon if $zoning_rezoningRecord's 'status' ($record['status']) is not equal to $zoning_rezoning_statusRecord's 'num' ($statusicon['num']) until it found a match. 
For example:

foreach ($zoning_rezoningRecords as $record){
   foreach ($zoning_rezoning_statusRecords as $statusicon){
      if ($record['status'] != $statusicon['num']) { continue; } // skip

      // insert code for displaying the icon here

      break;
   }
}

Hope that helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com