Favorites and Multiple Sections
4 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 13, 2016 (RSS)
By Toledoh - May 11, 2016
Hi Guys.
Is it possible to have the favorites plugin work with multiple tables?
I've got a table for "Alpine" activities and another table with "Snow Board" Activities. Alpine Activities have a detail page alpine.php, and Snow Board have snowboard.php.
I can "add" favorites as normal on both pages - however to create a list, how do I show them? Currently:
<?php foreach ($favoriteRecords as $record): ?>
<?php
$tableOrTag = 'XXX'; // Update with your section's table name
$recordNum = $record['num']; // Update this with current record number
$recordName = $record['label']; // Update this with current record number
$recordIcon = $record['icon']; // Update this with current record number
?>
<div class="col-xs-4">
<a href="XXX.php?num=<?php echo $recordNum ?>">
<div class="thumbnail">
<span class="icon-icon_<?php echo $recordIcon ?>" aria-hidden="true"></span>
<div class="caption"><?php echo $recordName ?></div>
</div>
</a>
</div><?php endforeach; ?>
Tim (toledoh.com.au)
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!
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/