This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

[SOLVED] adding up values

Help for those learning Tcl or writing their own scripts.
Post Reply
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

[SOLVED] adding up values

Post by raider2k »

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 :)
Last edited by raider2k on Sun Apr 05, 2009 9:53 am, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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
r
raider2k
Op
Posts: 140
Joined: Tue Jan 01, 2008 10:42 am

Post by raider2k »

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 :)
Post Reply