Add up total of custom field values
Posted: 03 April 2007 05:32 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  223
Joined  01-14-2006

Hi, I have a custom field called ‘points’. Each user uses a pulldown menu to select a number from 1 to 10. Users can publish as many entries/points as they like.
 
I’d like to know how to add up the numbers entered by a particular user to give them a ‘total’ for all ‘points’ entered into the weblog..
 
If I knew some php I’m sure it would be easy smile.. can anyone help pls..
many thanks,
Iain.

 Signature 

Weblog | New Zealand Web Design Agency

Profile
 
 
Posted: 03 April 2007 07:15 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  223
Joined  01-14-2006

hmm, after some reading (php for dummies lol) i found some code that I’d thought would work:
 

<?php
$a
= array( {exp:weblog:entries weblog="cpd_points" status="Approved" username="CURRENT_USER"}{cpd_points}, {/exp:weblog:entries} );
echo
"sum(a) = " . array_sum($a) . "\n";
?>


But all I get is a blank page… I’ve tried enabling php on input and output..?..
I gotto go to bed… gulp

 Signature 

Weblog | New Zealand Web Design Agency

Profile
 
 
Posted: 03 April 2007 02:18 PM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23528
Joined  05-20-2002

Hm- I think I’d use a query- a lot leaner for something like this.  But going with this- what’s the result of just:

{exp:weblog:entries weblog="cpd_points" status="Approved" username="CURRENT_USER"}{cpd_points}, {/exp:weblog:entries}


And if this was going to work?  PHP would definitely need to be parsed on output.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 03 April 2007 04:26 PM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  223
Joined  01-14-2006

Hi Robin,
The output is something like:
5, 8, 1, 10, 15, 18, 16,
thanks,

Iain.

 Signature 

Weblog | New Zealand Web Design Agency

Profile
 
 
Posted: 04 April 2007 01:56 PM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23528
Joined  05-20-2002

Hm- well the code works when I hard code it.  So while I’d still go with a query, try:

<?php
$a
= array( {exp:weblog:entries weblog="cpd_points" rdf="off" status="Approved" username="CURRENT_USER"}{cpd_points}, {/exp:weblog:entries} );
echo
"sum(a) = " . array_sum($a) . "\n";
?>


It will have to be parsed on output for sure.  If that doesn’t work- put just the weblog tag in a test template again- this time, look at the ‘reveal code’- make sure nothing else is getting in there- such as spaces, etc.

Don’t really have a good way to test this myself, so I’m winging it a bit.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64942 Total Logged-in Users: 61
Total Topics: 81920 Total Anonymous Users: 38
Total Replies: 440344 Total Guests: 279
Total Posts: 522264    
Members ( View Memberlist )