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