View Full Version : Help Needed
ChrisBaktis
03-20-2005, 10:29 PM
Does anyone know a way to take the numerical value of a custom profile field of all the members and add them up and print it out?
ChrisBaktis
03-22-2005, 06:05 PM
anyone?
Marco van Herwaarden
03-22-2005, 07:04 PM
SELECT SUM(fieldx) from userfield
ChrisBaktis
03-22-2005, 08:32 PM
Is there a way for this total to show on one of my pages on the site (home page for example)?
Marco van Herwaarden
03-22-2005, 08:37 PM
On any vB powered page (script) you could add a:
$sum_userfield = $DB_site->query("SELECT SUM(fieldx) FROM " . TABLE_PREFIX . "userfield");
Now you can use $sum_userfield in your template or echo it out on another way.
ChrisBaktis
03-22-2005, 11:44 PM
in a template would I just need to put '$sum_suerfield' where I want it to show up or do I need to use something like $post?
Marco van Herwaarden
03-23-2005, 03:26 AM
If you make sure the above code is in the script that evaluate the template, and that it is executed before the template is called, then yes.
ChrisBaktis
03-23-2005, 12:18 PM
Sorry to be a pain but yes to which one - using $sum_userfield by itself or using it like $post[sum_userfield] ?
My plans for now (while the board is smaller) to put this in the Navigational Bar - I will add your code to the global.php file. Can you tell me what I would need to use based on that info?
Anyone?
Marco van Herwaarden
03-25-2005, 07:33 PM
Change that query to:
$sum_userfield = $DB_site->query_first("SELECT SUM(fieldx) as total FROM " . TABLE_PREFIX . "userfield");
Then use $sum_userfield[total] in your template.
ChrisBaktis
03-25-2005, 11:06 PM
Thanks!
ChrisBaktis
12-03-2005, 02:18 AM
Where in the global.php file can I put the above db query? seems no matter where I put it it messes up the page.
Guest190829
12-03-2005, 02:33 AM
What do you mean by messing up the page? Did you put it in a plug-in or are you editing the actual file?
ChrisBaktis
12-03-2005, 03:20 AM
I was editing the file - Im very new to 3.5.1 and not sure how to do it as a plug in.
Guest190829
12-03-2005, 03:26 AM
Well I'm not really sure what your doing but you would put that code in global_start or global_complete. Please note that will run the query on every page...
ChrisBaktis
12-03-2005, 03:31 AM
I really only want this on the forum home page.
So to do the plug in can use the: forumhome_start
and the only code I would need is to put the above code?
All im trying to do is take the total from a custom profile field that all the members have and print out the total on the forum home page. Maybe you can clarify what I need to do.
tnguy3n
12-03-2005, 05:15 AM
change the query to:
$sum_userfield = $db->query_first("SELECT SUM(fieldx) as total FROM " . TABLE_PREFIX . "userfield");
I would use forumhome_complete rather than forumhome_start.
In FORUMHOME template, place $sum_userfield in wherever you want to show it.
Marco van Herwaarden
12-03-2005, 06:24 AM
The above code is for vB3.0. For 3.5 you would need something like:
$sum_userfield = $vbulletin->db->query_first("SELECT SUM(fieldx) as total FROM " . TABLE_PREFIX . "userfield");
ChrisBaktis
12-03-2005, 12:37 PM
works like a charm - thanks for all the help!
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.