Results 1 to 7 of 7

Thread: Calculating totals within a HTML table

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    98

    Question 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?

  2. #2
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334
    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.

  3. #3
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    Just use a variable to add up the total as as you move through the recordset.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    98
    Can you display your example with code for the table...

  5. #5
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    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

  6. #6
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334
    yeah, how about you show us some source, at least your query, or else we don't know what you're working with...

  7. #7
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    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
  •  



Click Here to Expand Forum to Full Width