Search code examples
vbscriptasp-classicadodb

Show the total of a column in the top of a table


I have a table and content of the column are coming from a Database. In the bottom of the table I am able to show the total value as well. But I want to show the total at the top of the table because sometimes there are hundreds of Rows, and to see the total I have to scroll to the end.

Is that even possible?

I have tried the below code. Which is giving me the total at the end of the table. But I want to show the total at the top of the table

<Table>
// This will create the column names
// I need to get the Total here above these column names
<tr>
  <td> Product </td>
  <td> Qty </td>
  <td> Price </td>
</tr> 

<% set ObjRS =ObjConn.execute ( "select * from pricetable")
 total= 0
 Do while Not ObjRS.EOf
  product = objrs("product")
  qty = objrs("Quantity")
  price = ObjRS("price")
  total = total+ price
  response.write "<td>" & product & "</td><td>" & qty & "</td><td>" & price & "</td><td>"

objrs.movenext
loop

response.write "<tr><td> & Total & </tr></td>

</table>

Solution

  • from

    response.write "<tr><td> & total & </td></tr>"
    

    to

    response.write "<thead><tr><th> & total & </th></tr></thead>