%
option explicit
Response.Buffer = False
Response.CacheControl = "private"
Dim intQuestionId
Dim intChoiceId
Dim sqlrecordvote
Dim BlnCheck
Dim strConnection
Dim conn
Dim vote_cookie
Dim Bnlvote
Dim SqlSelectVoteQuestion
Dim adoQuestion
Dim strVoteQuestion
Dim SqlChoice
Dim adoChoice
Dim strChoices
Dim sqlStats
Dim adoStats
Dim count
Dim total
Dim result
Dim sum
Dim sqlChoiceCount
Dim intCount
Dim adoCount
count = 0
Bnlvote=""
'Live
strConnection = "Driver={MySQL ODBC 3.51 Driver}; Server=dedi48.flk1.host-h.net; Database=voiceofthecape; UID=vocfma_1; PWD=MJHEufA5; Option=3"
'Localhost
'strConnection = "Driver={MySQL ODBC 3.51 Driver}; Server=dedi48.flk1.host-h.net; Database=voiceofthecape; UID=; PWD=; Option=3"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open(strConnection)
intQuestionId = trim(Request.QueryString("intQuestionId"))
intChoiceId = trim(Request.QueryString("intChoiceId"))
call drop_vote_cookie(intQuestionId)
Sub drop_vote_cookie(intQuestionId)
If request.Cookies("vote") = "" Then
Response.Cookies("vote") = intQuestionId
Response.Cookies("vote").Expires = now() + 365
Else
If instr(request.Cookies("vote"), trim(intQuestionId)) > 0 Then
Bnlvote = "vote"
Else
vote_cookie = request.Cookies("vote")
Response.Cookies("vote") = vote_cookie & "|" & intQuestionId
Response.Cookies("vote").Expires = now() + 365
End IF
End if
End sub
Function Insert_vote(Byval intChoiceId, Byval intQuestionId)
If intChoiceId > 0 then
sqlrecordvote = "insert into vote_responses (choiceId, questionId) values (" & intChoiceId & "," & intQuestionId & ")"
Conn.Execute(sqlrecordvote)
End If
End Function
Sub Display_Poll_Ouestion()
SqlSelectVoteQuestion = "select * from vote_questions as a where a.voteid = " & intQuestionId & " LIMIT 0,1;"
Set adoQuestion = Conn.Execute(SqlSelectVoteQuestion)
If not adoQuestion.EOF then
strVoteQuestion = adoQuestion("VoteQuestion")
end if
adoQuestion.Close()
set adoQuestion = nothing
End sub
call Display_Poll_Ouestion
sqlChoiceCount = "select count(choiceid) as total from vote_responses where questionid = " & intQuestionId & ""
Set adoCount = Conn.Execute(sqlChoiceCount)
If not adoCount.eof then
intCount = adoCount("total")
Else
intCount = 0
End if
adoCount.close
set adoCount =nothing
Sub Generate_vote_stats(intchoiceId)
result= 0
sqlStats = "select count(questionid) as total, choiceid from vote_responses where choiceid = " & intChoiceId & " group by choiceid, questionid;"
Set adoStats = Conn.Execute(sqlStats)
If not adoStats.eof then
Result = round(((adoStats("total")/intCount ) * 100),1)
End If
adoStats.close
set adoStats = nothing
End sub
%>
<%
SqlChoice = "select a.*"
SqlChoice = SqlChoice & " from vote_choices as a "
SqlChoice = SqlChoice & "where a.voteId = "& trim(intQuestionId) &""
set adoChoice = Conn.Execute(SqlChoice)
%>
<%
If not adoChoice.EOF Then
While not adoChoice.eof
strChoices = adoChoice("choice")
call Generate_vote_stats(adoChoice("id"))
%>
|
|
<%
adoChoice.movenext
Wend
End if
adoChoice.close
set adoChoice =nothing
%>
|
<%If Bnlvote <> "vote" then
Insert_vote intChoiceId,intQuestionId
else
If Bnlvote = "vote" then
Response.Write "Only one ballot per vote."
End If
End If%>
|
CLOSE |
| |