Favorites Plug-in: Count listings
6 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: July 25, 2011 (RSS)
By gversion - June 28, 2011
I've just bought the Favorites Plug-in and I'd like to display the total number of Favorites that a user has.
I'd be really grateful if someone could someone please tell me how to achieve this.
Thanks,
Greg
Re: [gversion] Favorites Plug-in: Count listings
By robin - June 29, 2011
The data for Website Favorites is stored in a hidden table called "_website_favorites". You can see it in the Section Editor. I've included an example below of displaying how many favourites a user has. In this case it's user with num of 1.
// load records
list($_website_favoritesRecords, $_website_favoritesMetaData) = getRecords(array(
'tableName' => '_website_favorites',
'where' => "createdByUserNum='1'"
));
echo $_website_favoritesMetaData['totalRecords'];
Hope that helps,
Robin
Programmer
interactivetools.com
Re: [robin] Favorites Plug-in: Count listings
By gversion - June 29, 2011
Many thanks for the help. I seem to have got this to work! :)
Thanks again for all your help.
Regards,
Greg
Re: [gversion] Favorites Plug-in: Count listings
By gversion - July 22, 2011
Could you please tell me how to update the code you provided so that it displays the total number of listings for the currently logged in user?
The example you provided was just for a user with UserNum='1'
Thank you,
Greg
Re: [gversion] Favorites Plug-in: Count listings
By gversion - July 22, 2011
I seem to have got this working by changing the code to be as follows:
<?php
// load favorites records
list($_website_favoritesRecords, $_website_favoritesMetaData) = getRecords(array(
'tableName' => '_website_favorites',
'where' => "createdByUserNum= '".mysql_escape($CURRENT_USER['num'])."'"
));
?>
Unsure if that's the way you would have suggested, but it appears to work! :)
Thanks,
Greg
Re: [gversion] Favorites Plug-in: Count listings
By robin - July 25, 2011
That looks good to me. $CURRENT_USER['num'] is exactly what I would use.
Robin
Programmer
interactivetools.com