| View previous topic :: View next topic |
| Author |
Message |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Sun Apr 05, 2009 7:12 am Post subject: [SOLVED] adding up values |
|
|
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 |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sun Apr 05, 2009 9:26 am Post subject: |
|
|
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 |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Sun Apr 05, 2009 9:53 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
|