Feature Gallery Photo on other site pages

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 25, 2013   (RSS)

By Mikey - March 23, 2013

So I've been messing around with 'where' trying to get this to work. It works just as I need it to if I hard code %Visitors% into the ('where'   => " gallery_category LIKE '%Visitors%' ",) as seen in bold black.

But I need to make this dynamic, so that I can choose one category from a list various category options and have the the were statement update according to category selected. So if in the "Home Page" section of my site, I change my category from "Visitors" to "Guest" then the latest photo associated with "Guest" uploaded to the photo gallery will be displayed on the Home Page of my website. Something like what can bee seen in bold red.

Anyone have any suggestions to make this dynamic in the WHERE clause?

  // load record from 'gallery'
  list($galleryFeaturedRecords, $galleryFeaturedMetaData) = getRecords(array(
    'tableName'   => 'gallery',
    //'where'       => '', // load first record
    'where'       => " gallery_category LIKE '%Visitors%' ",
    //'where'       => 'gallery_category LIKE '.$home_pageRecord['feature_gallery_category:label'],
    'loadUploads' => true,
    //'allowSearch' => true,
    'limit'       => '1',
  ));
  $galleryFeaturedRecord = @$galleryFeaturedRecords[0]; // get first record

Hi Zick,

It looks like you're on the right path. I think you just need to modify your code so it looks like this:

  // load record from 'gallery'
  list($galleryFeaturedRecords, $galleryFeaturedMetaData) = getRecords(array(
    'tableName'   => 'gallery',
    //'where'       => '', // load first record
    'where'       => " gallery_category LIKE '%Visitors%' ",
    'where'       => "gallery_category LIKE '%".$home_pageRecord['feature_gallery_category:label']."%'",
    'loadUploads' => true,
    //'allowSearch' => true,
    'limit'       => '1',
  ));
  $galleryFeaturedRecord = @$galleryFeaturedRecords[0]; // get first record

So I've added apostrophes around the string, and added the percent signs on the inside of the string so that MySQL knows that it can look for this variable anywhere in the field.

Let me know if you have any questions.

Thanks!

Greg 

Greg Thomas







PHP Programmer - interactivetools.com