Favorites and Multiple Sections

4 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 13, 2016   (RSS)

By ross - May 12, 2016

Hi Tim

Thanks for posting. There are a couple options for displaying favorites from two or more tables.

To start, you'll need to separately load the favorites from each table.  For example:

Load favorites from the first table:

    // get list 1 favorite record nums
    $tableOrTag        = mysql_escape('list1');  // update this with your table or tag name
    $currentUserNum    = mysql_escape( @$CURRENT_USER['num'] );
    $favoriteNumsQuery = "SELECT recordNum FROM `{$TABLE_PREFIX}_website_favorites` WHERE tableOrTag = '$tableOrTag' AND createdByUserNum = '$currentUserNum'";

    // load matching records
    list($favoriteList1Records) = getRecords(array(
      'tableName'     => 'sample_multi_record', // update this with your table or tag name
      'perPage'       => '10',
      'where'         => " num IN ($favoriteNumsQuery) ",
      'loadCreatedBy' => false,
      'allowSearch'   => false,
    ));

Then, load favorites from the second table:

// get list 2 favorite record nums
    $tableOrTag        = mysql_escape('list2');  // update this with your table or tag name
    $currentUserNum    = mysql_escape( @$CURRENT_USER['num'] );
    $favoriteNumsQuery = "SELECT recordNum FROM `{$TABLE_PREFIX}_website_favorites` WHERE tableOrTag = '$tableOrTag' AND createdByUserNum = '$currentUserNum'";

    // load matching records
    list($favoriteList2Records) = getRecords(array(
      'tableName'     => 'another_multi_section', // update this with your table or tag name
      'perPage'       => '10',
      'where'         => " num IN ($favoriteNumsQuery) ",
      'loadCreatedBy' => false,
      'allowSearch'   => false,
    ));

Notice how I've loaded each set of favorites into different variables: $favoriteList1Records and $favoriteList2Records

Now you have two different lists of favorites and can display them individually or you can us "array_merge($favoriteList1Records, $favoriteList2Records)" to combine them and have one big list. 

Does that make sense?

Let me know any questions.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Toledoh - May 12, 2016

Thanks Ross - sometimes I think I start looking for an issue, ignoring the simple solutions!

Cheers,

Tim (toledoh.com.au)

By ross - May 13, 2016

Hi Tim

Glad that helped. Let me know if there is anything else I can lend a hand with :).

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/