Hej jeg har lånt en bog der hedder ASP & SQL og der noget kode i bogen en afstemning
skriver koderne
den her er polltest.asp
<% OPTION EXPLICIT %>
<!-- #INCLUDE FILE="connect.asp" -->
<html><head><title>Afstemning</title></head><body>
<%
dim intPollID ' indeholder id på aktuel afstemning
' -1 hvis ingen afstemning
dim strPollName ' indeholder navn/overskrift/spørgsmål
Init ' Find pollid etc.
if request("pollAnswerID") <> "" then
Vote cint(request("pollAnswerID"))
ShowPollResult
else
ShowPoll
end if
' -------------------------------------
' Funktioner/procedurer
' -------------------------------------
sub Init
dim objRS, strSQL
strSQL = "SELECT pollid, pollname FROM PollInfo " & _
"WHERE startdate <= getdate() AND " & _
"enddate >= getdate()"
set objRS = Server.CreateObject("ADODB.Recordset")
with objRS
.open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
if .EOF then
intPollID = -1
strPollName = ""
else
intPollID = .Fields("pollid")
strPollName = .Fields("pollname")
end if
.close
end with
set objRS = Nothing
end sub
sub Vote (intAnswerID)
dim objCMD, strSQL
strSQL = "UPDATE PollAnswers SET votes = votes + 1 " & _
"WHERE refpollid = " & intPollID & " AND answerid = " & intAnswerID
set objCMD = Server.CreateObject("ADODB.Command")
with objCMD
.ActiveConnection = strConnect
.CommandType = adCmdText
.CommandText = strSQL
.Execute
end with
set objCMD = Nothing
end sub
sub ShowPoll
dim objRS, strSQL
response.write "<h4>" & strPollName & "</h4>"
strSQL = "SELECT answerid, answer FROM PollAnswers " & _
"WHERE refpollid = " & intPollID
set objRS = Server.CreateObject("ADODB.Recordset")
with objRS
.open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
while not .EOF
response.write _
"<a href='polltest.asp?pollanswerid=" & .Fields("answerid") & "'>" & _
.Fields("answer") & "</a><br>"
.movenext
wend
end with
set objRS = Nothing
end sub
sub ShowPollResult
dim objRS, strSQL
dim intTotal
intTotal = intTotalVotes
response.write "<h4>" & strPollName & "</h4>"
strSQL = "SELECT votes, answer FROM PollAnswers " & _
"WHERE refpollid = " & intPollID
set objRS = Server.CreateObject("ADODB.Recordset")
with objRS
.open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
while not .EOF
response.write .Fields("answer") & _
" (" & .Fields("votes") & " / " & _
round(100 * cdbl(.Fields("votes")) / cdbl(intTotal)) & "%)<br>"
.movenext
wend
end with
set objRS = Nothing
response.write "Stemmer i alt: " & intTotal & "<br>"
end sub
function intTotalVotes
dim objRS, strSQL, intResult
strSQL = "SELECT Sum(votes) AS totvotes FROM PollAnswers " & _
"WHERE refpollid = " & intPollID
set objRS = Server.CreateObject("ADODB.Recordset")
with objRS
.open strSQL, strConnect, adOpenForwardOnly, adLockReadOnly, adCmdText
if not .EOF then
intResult = cint(.Fields("totvotes"))
else
intResult = 0
end if
end with
set objRS = Nothing
intTotalVotes = intResult
end function
%>
</body></html>
og den anden
som hedder create_poll_tables.sql
use TTASP
CREATE TABLE PollInfo (
pollid int identity NOT NULL PRIMARY KEY,
pollname varchar(250) NOT NULL,
startdate datetime NOT NULL,
enddate datetime NOT NULL
)
CREATE TABLE PollAnswers (
answerid int identity NOT NULL PRIMARY KEY,
refpollid int NOT NULL,
answer varchar(250) NOT NULL,
votes int NOT NULL DEFAULT 0
)
HVAD KAN DER VÆRE GALT
ps. mens i nu kigger så forklar mig lige en gang for alle det med de der point om det er nogle man køber og uddeler eller det bare er nogle man kan give jeg skriver 50 fordi jeg ikke ved hvad det er håber i kan hjælpe med begge parter
der står noget med en connect.asp men ingen kode ?
Indlæg senest redigeret d. 21.07.2006 16:45 af Bruger #8715