Dynamic Counter for Total Number of Website Favorites
4 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: January 27, 2011 (RSS)
By Rusty - January 26, 2011 - edited: January 26, 2011
Have to call up the website favorites records
// get favorite record nums
$tableOrTag = mysql_escape('forms'); // 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($favoriteRecords, $favoriteMetaData) = getRecords(array(
'tableName' => 'forms', // update this with your table or tag name
// 'perPage' => '10',
'where' => " num IN ($favoriteNumsQuery) ",
'loadCreatedBy' => false,
'allowSearch' => false,
));
And here is the counter.
<?php
$cart_count = 0;
foreach ($favoriteRecords as $record) {
$cart_count++;
}
echo $cart_count;
?>
Is there a way to, or does anyone know of a way to dynamically update the counter, so that as a user adds or removes a Favorite, that the counter will immediately w/o refreshing the page update the current count.
Re: [Rusty] Dynamic Counter for Total Number of Website Favorites
By Jason - January 26, 2011
To do this without refreshing the page, you'll need to create your own jQuery function that will call a php script that will calculate your total for you.
This isn't too complicated, but does go a little beyond what we can handle in the forum. If you're interested, please send an email to consulting@interactivetools.com and we can give you some options on how to proceed.
Hope this helps.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] Dynamic Counter for Total Number of Website Favorites
By Rusty - January 27, 2011
Blue Code is commented out original. Red Code is the udpated code, Red Bold Code is the code I added.
$onClick = '';
//if ($action == 'add') { $onClick = "wsf_add('$escapedTableOrTag','$escapedRecordNum'); return false;"; }
if ($action == 'add') { $onClick = "wsf_add('$escapedTableOrTag','$escapedRecordNum', true); return false;"; }
elseif ($action == 'addAndReload') { $onClick = "wsf_add('$escapedTableOrTag','$escapedRecordNum', true); return false;"; }
//elseif ($action == 'remove') { $onClick = "wsf_remove('$escapedTableOrTag','$escapedRecordNum'); return false;"; }
elseif ($action == 'remove') { $onClick = "wsf_remove('$escapedTableOrTag','$escapedRecordNum', true); return false;"; }
elseif ($action == 'removeAndReload') { $onClick = "wsf_remove('$escapedTableOrTag','$escapedRecordNum', true); return false;"; }
else { $onClick = "alert('Unknown action specified! Must be add, remove, or removeAndReload!'); return false;"; }
The only thing to remember when modifying the code like this is that it will ALWAYS reload no matter which function, whether add, or addAndReload, / remove, removeAndReload.
Re: [Rusty] Dynamic Counter for Total Number of Website Favorites
By Jason - January 27, 2011
Glad to hear that's working for you.
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/