Display select uploads from one category on another category page using pulldown (multi value) list

2 posts by 1 authors in: Forums > CMS Builder
Last Post: July 24, 2017   (RSS)

By Mikey - July 24, 2017

I need to create a solution to display "Partner Logos" on "Solutions Pages".

In the CMS I have a category section editor set up for "Partners". In each partner record there's an upload field 'partner_logo' to upload a logo for the partner. I have another category section editor set up called "Solutions". In solutions there's a "pulldown (multi value)" list for selecting which partners should be listed on an individual solutions page.

I tried the code below, but my searchString is not working and will not display any partner logos at all. I suspect it's written incorrectly, but I can't get this figured out. Anyone have any suggestions?

  // load record from 'solutions'
  list($solutionsRecords, $solutionsMetaData) = getRecords(array(
    'tableName'   => 'solutions',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $solutionsRecord = @$solutionsRecords[0]; // get first record
  if (!$solutionsRecord) { dieWith404("Record not found!"); } // show error message if no record found


 ///////////////// solutionsRecord /////////////////
   $searchString = '';
  //Create the where statement to be used to filter partners
  
  //if partners values have been selected....
  if(is_array(@$solutionsRecord['partners:values'])){
    //Count the total number if items in the array.....
    $arrayCounter = count($solutionsRecord['partners:values']);
    //Loop through the array....
    foreach($solutionsRecord['partners:values'] as $key => $filterItem){
      //create the search string that searches the "partner records" for the num value....
      $searchString .= "num LIKE '%\t$filterItem\t%'";
      //If this is not the last item to filter by, add or to the statement....
      if(($key+1) != $arrayCounter){
        $searchString .= " OR ";
      }
    }  
  }
///////////////// partnersRecords /////////////////

  // load records from 'partners'
  list($partnersRecords, $partnersMetaData) = getRecords(array(
    'tableName'   => 'partners',
    'where'       => $searchString,
    'loadUploads' => true,
    'allowSearch' => false,
  ));

<?php foreach ($partnersRecords as $record): ?>
    <?php foreach ($record['partner_logo'] as $index => $upload): ?>
    <img src="<?php echo htmlencode($upload['thumbUrlPath4']) ?>" alt="<?php echo $record['name'] ?>" />
<?php endforeach ?>
<?php endforeach ?>

Thanks, Zicky