Related Pages using leftJoin?

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 22, 2020   (RSS)

By gregThomas - June 22, 2020

Hey Tim,

Your method would work great, the only change I would make is to check the related_pages values exist before imploding them, or you might get an error:

<?php

  // load record from 'pages'
  list($pagesRecords, $pagesMetaData) = getRecords(array(
  'tableName'   => 'pages',
  'where'       => '`num` =' .$selectedCategory['num'],
  'loadUploads' => true,    'allowSearch' => false,
  'limit'       => '1',
  ));

  $pagesRecord = @$pagesRecords[0]; // get first record
  if (!$pagesRecord) { dieWith404("Record not found!"); } // show error message if no record found

  if (!empty($related['related_pages:values'])) {
    $relatedNums = implode(", ", $related['related_pages:values']);
    if($relatedNums) { $pagesRecord['related_pages:records'] = mysql_select('pages', "`num` IN ($relatedNums)"); }
  }

I also noticed that the HTML contains an image URL, so you might need to swap out the mysql_select for a getRecords so that the upload records are included.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Toledoh - June 22, 2020

Thanks Greg - Great!

Cheers,
Tim (toledoh.com.au)