Related item on a detail page

11 posts by 2 authors in: Forums > CMS Builder
Last Post: January 7, 2020   (RSS)

By daniel - January 7, 2020

Hi mbareara,

If you use a multi-select field to store more than one city, this changes how the data is saved, and so it requires a different method to filter. This isn't something easily done within getRecords(), so instead, you'll need to handle both the city and record limit filters within the loop. It would look something like this:

<?php 
  list($localiRecords, $localiMetaData) = getRecords(array( 
    'tableName' => 'locali',
    'where' => mysql_escapef('num != ?', $localiRecord['num']),
  ));
  
  $filterCities = listValues_unpack($localiRecord['city']);
  $recordLimit = 4;
  $recordCount = 0;
?>
<?php foreach ($localiRecords as $record): ?>
  <?php 

    $recordCities = listValues_unpack($record['city']);
    $cityMatch = false;
    foreach ($filterCities as $city) {
      if (in_array($city, $recordCities)) {
        $cityMatch = true;
        break;
      }
    }
    if (!$cityMatch) { continue; }
  
    if ($recordCount++ >= $recordLimit) { break; }
    
  ?>

Note that this hasn't been tested so it may take some tweaks to get working, but hopefully it is close! Let me know if you have any more questions.

Thanks,

Daniel
Technical Lead
interactivetools.com