Dynamic Counter for Total Number of Website Favorites

By Rusty - January 26, 2011 - edited: January 26, 2011

So I have what I would call a static counter for the total number of website favorites currently added to the CMS. It works in a sort of static manner, in so much that it ONLY updates when the user loads/reloads the page. It doesn't dynamically /immediately update as a user adds an item to Favorites. Check it out:
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.
Rusty

Re: [Rusty] Dynamic Counter for Total Number of Website Favorites

By Jason - January 26, 2011

Hi Rusty,

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: [Rusty] Dynamic Counter for Total Number of Website Favorites

By Jason - January 27, 2011

Hi Rusty,

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/