<% 'Dimension variables Dim adoCon 'Database Connection Variable Dim rsWeeklyPoll 'Database Recordset Variable to hold the eweekly poll recordset Dim strAccessDB 'Holds the Access Database Name Dim strSQL 'Database query sring Dim strPollQuestion 'Holds the poll question Dim intPollIDNum 'Holds the Poll ID Num Dim intSelectionLoopCounter 'Loop counter to display the poll selections Dim intVotedIDNo 'Holds the ID Number the last vote the user voted in if there is one Dim blnCheckForPoll 'Set to false if there are no weekly polls in the database Dim blnAlreadyVoted 'Set to true if the user has voted in this weeks poll 'Error Trapping On Error Resume Next 'Intilaise variables blnCheckForPoll = True blnAlreadyVoted = False intPollIDNum = 1 'Initialise the strAccessDB variable with the name of the Access Database strAccessDB = "weekly_poll.mdb" 'Create a connection odject to the database Set adoCon = Server.CreateObject("ADODB.Connection") Set rsWeeklyPoll = Server.CreateObject("ADODB.Recordset") 'Open connection to the database driver adoCon="DRIVER={Microsoft Access Driver (*.mdb)};" 'Open Connection to database adoCon = adoCon & "DBQ=" & server.mappath(strAccessDB) 'Initalise the strSQL variable with an SQL statement to query the database strSQL = "SELECT * FROM tblPolls ORDER By id_no DESC;" 'Query the database rsWeeklyPoll.Open strSQL, adoCon, 3 'Check there is a weekly poll to display If rsWeeklyPoll.EOF Then 'If there is no weekly poll in the database chenge the blnCheckForPoll variable to false blnCheckForPoll = False Else 'Read in the polling question from the database strPollQuestion = rsWeeklyPoll("Question") 'Read in the Weekly Poll ID number intPollIDNum = CInt(rsWeeklyPoll("id_no")) 'Loop round to read in the number of votes cast For intReadInVotesLoopCounter = 1 To 7 'Read in the total number of votes cast intToatalPollVotes = intToatalPollVotes + CInt(rsWeeklyPoll("Votes_" & intReadInVotesLoopCounter & "")) Next 'Check the user has not already voted by reading in a cookie from there system 'Read in the Poll ID number of the last poll the user has voted in intVotedIDNo = CInt(Request.Cookies("Poll")("PollID")) 'If the user has already voted then redirect them to the results page If intVotedIDNo = intPollIDNum Then blnAlreadyVoted = True End If %>
" Else 'If there are no votes yet then format the percent by 0 otherwise the sums corse problems If intToatalPollVotes = 0 Then dblPollVotePercentage = FormatPercent(0, 0) Else 'Read in the the percentage of votes cast for the vote choice dblPollVotePercentage = FormatPercent((rsWeeklyPoll("Votes_" & intSelectionLoopCounter) / intToatalPollVotes), 0) End If 'Display the selection choice results Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " Response.Write vbCrLf & " " End If End If Next %>
<% = strPollQuestion %>
<% 'If there is a weekly poll to display then write the HTML to display it If blnCheckForPoll = True Then 'Loop to display each of the selection choices for the poll For intSelectionLoopCounter = 1 To 7 'If there is a Selection choice then display the HTML to show it If NOT rsWeeklyPoll("Selection_" & intSelectionLoopCounter) = "" Then If blnAlreadyVoted = False Then 'Display a radio button for the selection choice Response.Write vbCrLf & "
" 'Display the selection choice Response.Write vbCrLf & " " & rsWeeklyPoll("Selection_" & intSelectionLoopCounter) & "
" & rsWeeklyPoll("Selection_" & intSelectionLoopCounter) & "
" & dblPollVotePercentage & "
<% 'If the user has not voted then display a vote button If blnAlreadyVoted = False Then %> <% 'Display the totla number of votes Else 'Display the total votes cast Response.Write vbCrLf & " Jumlah Pemberi Suara: " & intToatalPollVotes & "" End If 'Else if there is no weekly poll display the appropriate message Else Response.Write vbCrLf & "Tidak ada Polling untuk ditampilkan" End If 'Reset Server Objects Set adoCon = Nothing rsWeeklyPoll.Close Set rsWeeklyPoll = Nothing %>

Liat Hasil Polling