How do I sum colums of totals dynamically?

# Thread: How do I sum colums of totals dynamically?

1. DBG Guest

## How do I sum colums of totals dynamically?

I am new to ASP. I have a log book application that stores the daily values in the database. The ASP page displays the data for the current month only. How do I sum those values at the bottom of the page?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: How do I sum colums of totals dynamically?

Do you know any programming language? At all?<BR><BR>Because you can certainly do this in any language, including VBScript or JScript.<BR><BR>Simple as this:<BR><BR>&#060;%<BR>total1 = 0<BR>total2 = 0<BR>total3 = 0<BR><BR>Do Until RS.EOF<BR>&nbsp;&nbsp;&nbsp;&nbsp;value1 = RS("someField")<BR>&nbsp;&nbsp;&nbsp;&nbsp;value2 = RS("anotherField")<BR>&nbsp;&nbsp;&nbsp;&nbsp;valu e3 = RS("stillAnother")<BR>&nbsp;&nbsp;&nbsp;&nbsp;tota l1 = total1 + value1<BR>&nbsp;&nbsp;&nbsp;&nbsp;total2 = total2 + value2<BR>&nbsp;&nbsp;&nbsp;&nbsp;total3 = total3 + value3<BR>&nbsp;&nbsp;&nbsp;&nbsp;... now display the columns for this record ...<BR>&nbsp;&nbsp;&nbsp;&nbsp;RS.MoveNext &#039 to next record<BR>Loop &#039 end of loop on records<BR>... now display the totals ...<BR><BR>

3. DBG Guest

## RE: How do I sum colums of totals dynamically?

No need to be rude... I am a beginner to this...<BR><BR>Thank you for the help...

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## "Tone" is hard to do in messages

Wasn&#039t trying to be rude!<BR><BR>If you were more advanced, I was going to give you a different answer, that&#039s all!<BR><BR>I tried to make the first answer as simple and yet complete as possible, but if you are ready for something more advanced there are lots of other possible answers. That&#039s all.<BR><BR>Apologies if the "tone" sounded wrong; I assure you it wasn&#039t intentional. I guess I should have said the above in that first message.<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## 20 lashes with a wet ASP manual...

Ummm...I did phrase that very badly, now that I look at it again.<BR><BR>I started in one direction and then went typing off in another.<BR><BR>I meant to follow the whole thing up with a discussion of how you could convert the RecordSet to an array and then possibly more easily work with the array, if you were familiar with arrays. But as it is, I simply botched it up.<BR><BR>I&#039ll try to be more careful in the future.<BR><BR>

6. DBG Guest

## RE: 20 lashes with a wet ASP manual...

Thanks for the help, really... I put the example to my page, and got totals for the bottom row only hehe probably where I put the loop was wrong.. I have my code broken into two IF statements, using a class to add colored rows... I am really very new to all of this, and I am learning as I go.... I used to do everything with wizards, but IS is making do it all by hand so I learn it :-) And I am.... but I know absolutely no java and only very very basic vbscript... just enough to display values from the database to my page...

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## let's see if we can dry it out

Your loop was probably in the right place, but where you added to the totals was probably wrong.<BR><BR>Or maybe you did the adding wrong?<BR><BR>You did do <BR><BR>total1 = total1 + value1 <BR><BR>each time through the loop, didn&#039t you? Just doing<BR><BR>total1 = value1<BR><BR>would not do the right thing.<BR><BR>Anyway, I&#039d be glad to look at your code. If you wish, you can email (attachment fine) to billw@chilisoft.com<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## with hot air? ehhh...maybe not

just thought of something:<BR><BR>Another way to exhibit the symptoms you saw would be to be doing the <BR><BR>total1 = 0<BR>total2 = 0<BR>etc.<BR><BR>*inside* the loop. No, it must happen exactly once, *before* the loop.<BR><BR>This probably isn&#039t the problem, but figured it couldn&#039t hurt to make sure.<BR><BR>Hey! I also want to see how you are doing the alternating colors! I might be able to show you a trick there, as well. (Maybe not, but... I might note that my "trick" would let you use as many colors as you like...alternating between 3, 4, or whatever...without changing anything but the list of colors to use.)

9. rho Guest

## RE: with hot air? ehhh...maybe not

hi Bill,<BR><BR>why don&#039t u show that technique of changing the colors to me<BR><BR>-rho

10. DBG Guest

## RE: with hot air? ehhh...maybe not

I will send you an email with the attachment today :-) Thanks...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•