Forums

This topic is locked

calculations in asp and vbscript

Posted 07 Jan 2002 14:02:08
1
has voted
07 Jan 2002 14:02:08 David Behan posted:
ASP and VBSCRIPT

Ok, got a stored procedure that will update the "hits" field in the database when a user accesses a particular record. That is grand and I can get the number of hits for each record.

Now what I want to do is get a total number of all the hits added together. Basically add all of the individual hits of each record to get a total number of hits. If someone can give me some basic code for this, that would be great.

Next is I want to show what percentage of hits each record got. So, this will be divide field "hits" for record_id by total number of hits multiplied by 100. Can someone supply me with this script as well.

Cheeurs in advance.

Dave
~~~~~~~~~~~~~~~~~~~~~~

C:/Dos
C:/Dos/Run
Run/Dos/Run

Replies

Replied 08 Jan 2002 08:08:19
08 Jan 2002 08:08:19 Joel Martinez replied:
ok, youd be best to start this out in sql...<pre id=code><font face=courier size=2 id=code>SELECT sum(hits) FROM yourtable</font id=code></pre id=code>The code for the percentages would look something liek this<pre id=code><font face=courier size=2 id=code>SQL:
SELECT therecord, hits FROM yourtable</font id=code></pre id=code>then the code <pre id=code><font face=courier size=2 id=code>&lt;%
rsarray = recordset1.getrows
max = ubound(rsarray,2)

<font color=green>'first, get the total number of hits</font id=green>
dim total
total =0
for i=0 to max
total = total + rsarray(1,i)
next

<font color=green>'Write out a line for each record</font id=green>
for i=0 to max
therecord = rsarray(0,i)
hits = rsarray(1,i)
response.write therecord & " " & hits & " %" & (hits / total) * 100 & "&lt;br&gt;"
next
%&gt;</font id=code></pre id=code>I hope that was not too confusing... this code assumes that there is a recordset name recordset1 using the sql that I showed.

Joel Martinez [ ]
----------
E-Commerce Concepts with Ultradev...pre-order yours at
www.basic-ultradev.com/ecomm_concepts/

Reply to this topic