Dynamic content combining 2 sections

5 posts by 2 authors in: Forums > CMS Builder
Last Post: February 26, 2020   (RSS)

By robin - February 24, 2020

HI Carole,

You can use the product record to help get the right category automatically.  In the example below i used your product category variable ($productsRecord['category']) to search for the category.

 // load record from 'categories'
  list($categoriesRecords, $categoriesMetaData) = getRecords(array(
    'tableName'   => 'categories',
    'where' => " title='" . mysql_escape($productsRecord['category']) . "' ",
    'orderBy'     => 'RAND()',
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $categoriesRecord = @$categoriesRecords[0]; // get first record
  if (!$categoriesRecord) { dieWith404("Record not found!"); } // show error message if no record found

Hope that helps!  Please let me know any questions.  Thanks,

Robin

Robin
Programmer
interactivetools.com

Thanks, but that doesn't work.  It comes back to say "Record not found!"

By robin - February 25, 2020

Hi Carole,

hmmm so something isn't matching up here.  Is $productsRecord['category'] the variable that contains the category name?  If so - in the record that shows the category as not found, what's the value of $productsRecord['category']?

Thanks!
Robin

Robin
Programmer
interactivetools.com

Thanks for responding.  It works out now that I changed it to category (the products record which relates to category is the category, not the title).

'where' => " category='" . mysql_escape($productsRecord['category']) . "' ",

Thanks, resolved and working now.  Perfect.