Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Online Survey History

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
Greetings,

I have several online surveys of which I store questions and answers in a SQL database. I display these one at a time on the homepage using ASP.

Now my client would like to see a history of the past surveys and results on one page. I really don't know where to start. I've tried some loops, etc. but I just can't seem to get it right because there is a recordset for the question and a recordset for the answer.

Here's the code for displaying the results one at a time:

<%

sql_statement=&quot;SELECT SUM(total) FROM ans where poll_id=1&quot;
Set oRs = Server.CreateObject(&quot;ADODB.recordset&quot;)
oRs.Open sql_statement,Conn
'You will get directly the final total
final_total=oRs(0).value
ors.close
set ors=nothing
sql = &quot;select ansdesc,total from ans where poll_id=1 order by id&quot;
set Rs2 = conn.execute(sql)
response.write &quot;<table border=0 cellspacing='4'>&quot;
t=1
do while not rs2.eof
ans=rs2(&quot;total&quot;)
if ans=0 then
ansPercent=&quot;0%&quot;
else
ansPercent=formatpercent(ans/final_total)
end if
ansImage=replace(ansPercent,&quot;%&quot;,&quot;&quot;)
ansImage=ansImage*2
ansdesc=rs2(&quot;ansdesc&quot;)
response.write &quot;<tr><td>&quot;
response.write &quot;<b>&quot; & ansdesc & &quot;</b></td><td>&quot; & ansPercent
response.write &quot;</td><td>&quot;
response.write &quot;<img src=images/char&quot;&t&&quot;.gif width=&quot;&ansimage&&quot; height=5></tr></td>&quot;
rs2.movenext
t=t+1
loop
response.write &quot;</tr></td><tr><td colspan=3>&quot;
response.write &quot;Total Votes : &quot;&final_total & &quot;<p><input type=submit value=close onclick=window.close()></table>&quot;
%>

Any thoughts would be greatly appreciated. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top