|
-
Aug 27th, 2001, 04:15 PM
#1
Thread Starter
Lively Member
Calculating totals within a HTML table
I have a table that displays the rsults of a sql query. It would be nice to add the totals at the bottom of the table. anyone have ideas on how to do this?
-
Aug 27th, 2001, 04:32 PM
#2
Hyperactive Member
I don't know what scripting language you're using, but assuming you're using VBScript, just create a varialbe for each item plus another variable for the total, and calculate as such:
Dim item1, item2, item3, total
total = item1 + item2 + item3
And if you have a recordset object, you can just assign the value of the query to the items as such:
item1 = rs("Item1")
item2 = rs("Item2")
... etc
Hope this helped.
-
Aug 27th, 2001, 05:04 PM
#3
Hyperactive Member
Just use a variable to add up the total as as you move through the recordset.
-
Aug 27th, 2001, 05:34 PM
#4
Thread Starter
Lively Member
Can you display your example with code for the table...
-
Aug 27th, 2001, 06:51 PM
#5
Hyperactive Member
I'm not sure what you need to do specifically but here is a simple example:
rsRecordSet.Open "SELECT Name, Total FROM Table"
Dim iTotal as integer
iTotal = 0
Do while NOT rsRecordSet.EOF
Response.Write rsRecordSet("Name")
Response.Write rsRecordSet("Total")
iTotal = iTotal + rsRecordSet("Total")
rsRecordSet.MoveNext
Loop
Response.WRite "Total"
Response.Write iTotal
-
Aug 27th, 2001, 11:17 PM
#6
Hyperactive Member
yeah, how about you show us some source, at least your query, or else we don't know what you're working with...
-
Aug 30th, 2001, 12:45 AM
#7
Frenzied Member
Let your SQL server do the calculation.. add sum() columns at the end of your query and use them in your last row of your table.
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|