egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] adding up values

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Sun Apr 05, 2009 7:12 am    Post subject: [SOLVED] adding up values Reply with quote

hi there

this time im unsure about the way to go with something id like to do - quick example of the case:

theres a different number of users in a channel where some of them have been added to a database with personal stats. that means the ones who have been added to the database are also being rated by using numbers like one user has been rated with value 10, another one has been rated with value 200 and so on. now i want to sum up all the rated values which gets me somehow stuck.

usually im reading the values from database and then use foreach to get every value but how do i sum up each value with the value before?

im not sure if using arrays is a good idea, also played with the idea to write every value into a new line of a text file which will be read line for line and then summed up after the foreach part but im sure theres more beautiful solution to this.

please help Smile


Last edited by raider2k on Sun Apr 05, 2009 9:53 am; edited 1 time in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Apr 05, 2009 9:26 am    Post subject: Reply with quote

What kind of database storage are you using?
SQL databases usually have neat features for sums and such...

If you wish to sum it manually, try adapting this piece of code:
Code:
set sum 0
#Assume the data is stored in dataset as a list of lists...
foreach item $dataset {
 #second item of $item holds the rating...
 incr sum [lindex item 1]
}

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Sun Apr 05, 2009 9:53 am    Post subject: Reply with quote

oh very fine ^^
didnt know that i can add an additional value to incr $var

and yep - you assumed exactly the right thing, thanks for your help - works fine now Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber