Flere afstemninger på en side
Jeg har et problem.Jeg ønsker at vise alle afstemninger der er sat \"active\" på én side!
Hvordan gør jeg?
Nedenfor er sourcen!
vh Søren Peter
incpollmentor.asp:
<%
\'\'\'TODO for you! Configuration:
\'\'\'\'2. Database connection
Function PollMentor_GetDatabaseConn()
Dim oRet
Dim strDSN
strDSN = \"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\"& Server.MapPath(\"pollmentor97.mdb\")
Set oRet = Server.CreateObject (\"ADODB.Connection\")
oRet.Open strDSN
Set PollMentor_GetDatabaseConn = oRet
End Function
Function PollMentor_GetTitle()
PollMentor_GetTitle = \"Internationale Socialisters Ungdoms afstemning\"
End Function
\'\'\'TODO for you! Configuration:
\'\'\'\'3. Some ads if you\'d like
Function PollMentor_TryToVote( sID, nNumber )
Dim sRet, strSQL
Dim oConn
Set oConn = PollMentor_GetDatabaseConn()
\'Get real id...
Dim oRS
If sID = -1 Then
Set oRS = oConn.Execute(\"select id from poll where active=true\")
sID = oRS(\"id\").Value
oRS.Close
Set oRS= Nothing
End If
If PollMentor_CanUserVote( oConn, sID ) = False Then
sRet = \"Desværre har du allerede stemt!\"
Else
strSQL = \"update poll set count\" & nNumber & \" = count\" & nNumber & \" +1 where \"
If nNumber =-1 Then
strSQL = strSQL & \" active=true\"
Else
strSQL = strSQL & \" id=\" & sID
End If
oConn.Execute strSQL
oConn.Execute \"insert into votelog(poll_id, ip) values(\" & sID & \",\'\" & Request.ServerVariables( \"REMOTE_ADDR\" ) & \"\')\"
sRet = \"Tak for at du stemte\"
End If
oConn.Close
Set oConn = Nothing
PollMentor_TryToVote=sRet
End Function
Function PollMentor_CanUserVote( oConn, sID ) \'
\'Check of user already has voted within 24 hours?
\'If so then no voting can be done...
\' Here\'s your chance to display some other content
\'1. Check IP address
Dim strSQL, sTime, oRS
sTime = DateAdd( \"d\", -1, now() )
strSQL = \"select id from votelog where poll_id=\" & sID & \" AND datum > #\"&sTime & \"# AND ip=\'\" & Request.ServerVariables( \"REMOTE_ADDR\" ) & \"\'\"
\' Response.Write strSQL
Set oRS = oConn.Execute(strSQL)
If oRS.EOF Then
PollMentor_CanUserVote = True
Else
PollMentor_CanUserVote = False
End If
oRS.Close
Set oRS = Nothing
End Function
Function PollMentor_GetPollInfo ( ByVal nID, ByRef sTitle, ByRef sQuestion, ByRef vAnswers, ByRef vCount )
Dim sRet, strSQL
Dim oConn, oRS, nCount
Set oConn = PollMentor_GetDatabaseConn()
strSQL = \"select * from poll where \"
If nID = -1 Then
strSQL = strSQL & \" active=true\"
Else
strSQL = strSQL & \" id=\" & nID
End If
Set oRS = oConn.Execute(strSQL)
If oRS.EOF Then
PollMentor_GetPollInfo = False
Else
sTitle=PollMentor_GetTitle()
sQuestion=oRS(\"question\")
For nCount=1 To 8
vAnswers(nCount)=oRS(\"answer\" & CStr(nCount))
vCount(nCount)=oRS(\"count\" & CStr(nCount))
Next
PollMentor_GetPollInfo = True
End If
oRS.Close
Set oRS = Nothing
oConn.Close
Set oConn = Nothing
End Function
%>
pollmentor.asp:
<%
OPTION EXPLICIT
Response.Buffer = True
%>
<!--#include file=\"incpollmentor.asp\"-->
<%
\'Some before doings...
\'Lets get the current poll...
Dim sTitle
Dim sQuestion
Dim vAnswers(8)
Dim vCount(8)
\'Get active one...
PollMentor_GetPollInfo -1, sTitle, sQuestion, vAnswers, vCount
%>
<html>
<head>
<title>Afstemning</title>
</head>
<body>
<table border=\"0\" width=\"100%\">
<tr>
<td valign=\"top\">
<br>
<form method=\"POST\" action=\"pollmentorres.asp\">
<table border=\"1\" width=\"30%\" cellpadding=0 cellspacing=0>
<tr>
<td width=\"100%\" bgcolor=\"#444444\" align=\"center\"><b><font color=\"#FFFFFF\"><%=sTitle%></font></b></td>
</tr>
<tr>
<td width=\"100%\" bgcolor=\"#C0C0C0\" align=\"left\"><font size=\"1\"><br><%=sQuestion%></font><br><br>
<%
Dim nCount
Dim nDef
Dim nTotal
nTotal = 0
For nCount=1 To 8
If vAnswers(nCount) <> \"\" Then
nTotal = nTotal + vCount(nCount)
%>
<font size=\"1\"><input type=\"radio\" value=\"<%=nCount%>\" <%If nDef = False Then %>checked<%End If%> name=\"R1\"><%=vAnswers(nCount)%></font><br>
<%
nDef = True
End If
Next
%>
<p> </td>
</tr>
<tr>
<td width=\"100%\" bgcolor=\"#C0C0C0\" align=\"center\"><font size=\"1\"><input type=\"submit\" value=\"Stem!\" name=\"B1\"><br>
<a href=\"pollmentorres.asp\">Resultatet af afstemningen</a><br>
<a href=\"pollmentorhist.asp\">Tidligere afstemninger</a></font>
<p><font size=\"1\"><%=nTotal%> har stemt indtil videre </font></p>
</td>
</tr>
</table>
</form>
<p>
</td>
</tr>
</table>
</body>
</html>
