Load til samme side ?
Jeg har en afstemningsboks hvor en bruger kan stemme.Når der bliver stemt bliver der kaldt til
<%call VotingBooth%> (på index.asp siden)
Jeg vil gerne have at resultatet skal komme ind i samme tabel på index.asp, men som jeg har det lige nu skal jeg loade en side der hedder host.asp
Hvordan ændre jeg dette??
Her er scriptet som skal kaldes, og der står noget I måske kan bruge i linie 58:
<%Response.Expires = -10000%>
<!-- #include file="vb_vars.asp"-->
<%
' The user has cast a vote
' Let's deal with that here
if request.form("voted") = "true" then
'user sent a malformed request. Let's dump out.
if request.form("id") = "" then response.redirect VB_HOSTFILE
if ((VB_RESTRICT) and (request.cookies("vb") = "")) or NOT VB_RESTRICT then
'Either VB_RESTRICT is set to true and user DOES NOT have cookie or
'VB_RESTRICT is set to false. Thus, it's OK to vote.
'If VB_RESTRICT is true, write the cookie
if VB_RESTRICT then
'Cookie name is 'vb', expiry time of cookie is NOW + VB_TIMETORESTRICT
Response.Cookies("vb") = "vb"
Response.Cookies("vb").Expires = DateAdd("h", VB_TIMETORESTRICT, Now)
end if
' ==== BEGIN write new vote ==============================
' New stuff here: added feb 11, 2002
pollid = request.form("pollid")
answerid = request.form("id")
strSQL = "SELECT question.id, question.question, question.total, answer.vote, answer.id "
strSQL = strSQL & "FROM answer INNER JOIN question ON answer.parent = question.id "
strSQL = strSQL & "WHERE (((question.id)=" & pollid & ") AND ((answer.id)=" & answerid & "));"
'response.write STRSQL
'response.end
'Define and open the recordset in write mode (1,3,1)
set rst = Server.CreateObject("ADODB.Recordset")
rst.open strSQL, Connect, 1, 3, 1
' get values from recordset...
intQuestionId = rst("question.id")
strQuestion = rst("question")
intTotal = rst("total")
intAnsTotal = rst("vote")
intTotal = intTotal + 1
intAnsTotal = intAnsTotal + 1
rst("total") = intTotal
rst("vote") = intAnsTotal
rst.update
rst.close
connect.close
' End new stuff
' ==== END write new vote ====================================
else
'not ok to vote.
'Don't do anything
end if
'Whether or not a vote was cast, redirect to same page but display results.
'The poll to display is in the request.form variable 'pollid'.
intPollId = request.form("pollid")
response.redirect VB_HOSTFILE & "?id=" & intPollID & "&results=true"
end if
%>
<%
sub VotingBooth
'To debug cookies, un-rem (yes, that's now a verb!) the next line to expire cookie each time
'Response.Cookies("vb").Expires = Now() - 1
if (request.cookies("vb") <> "") and VB_RESTRICT then
call DisplayResults
else
Select case request("results")
Case "true"
Call DisplayResults
Case else
Call DisplayVote
end select
end if
end sub
%>
<%
sub DisplayVote
strSQL = "SELECT question.question, answer.answer, answer.id, question.id "
strSQL = strSQL & "FROM answer INNER JOIN question ON answer.parent = question.id "
strSQL = strSQL & "WHERE (((question.active)=True));"
set rst = Server.CreateObject("ADODB.Recordset")
rst.open strSQL, Connect, 3,1,1
if rst.RecordCount <> 0 then
strQuestion = rst("question")
intPollID = rst("question.id")
with response
.write "<table border=0 cellpadding=" & VB_TABLEPADDING & " align=" & VB_TABLEALIGN & "><tr><td align=left>"
.write "<form action=" & VB_URL & "/vb.asp method=post>"
.write "<table border=0 cellpadding=s cellspacing=2 width=" & VB_TABLEWIDTH & " align=" & VB_TABLEALIGN & " hspace=10 vspace=10 bgcolor=" & VB_COLOR2 & ">"
.write "<tr><td colspan=2 align=center bgcolor=" & VB_COLOR1 & "><font face=verdana size=1><b>" & strQuestion & "</b></td></tr>"
end with
do while not rst.EOF
with Response
.write "<tr><td align=left>"
.write "<input type=radio name=id value = " & rst("answer.id") & "></td>"
.write "<td align=left><font face=arial size=1>" & rst("answer") & "</font></td></tr>"
end with
rst.MoveNext
loop
rst.close
with response
.Write("<tr><td align=left colspan=2><INPUT TYPE=image src=billeder/knap_stem.gif width=38 height=13 border=0 VALUE=Send></td></tr>")
.write "<tr><td align=left colspan=2><font face=arial size=1>"
.write "</table>"
.write "<input type=hidden name=voted value=true>"
.write "<input type=hidden name=pollid value=" & intPollId & ">"
.write "</form></td></tr></table>"
end with
else
'response.write "<h2>No current poll</h2>"
end if
Connect.close
end sub
%>
<%
Sub DisplayResults
strSQL = "SELECT question.question, answer.answer, answer.vote, question.total "
strSQL = strSQL & "FROM answer INNER JOIN question ON answer.parent = question.id "
strSQL = strSQL & "WHERE (((question.active)=True));"
set rst = Server.CreateObject("ADODB.Recordset")
rst.open strSQL, Connect
strQuestion = rst("question")
intTotal = rst("total")
response.write "<table border=0 cellpadding=" & VB_TABLEPADDING & " align=" & VB_TABLEALIGN & ">"
response.write "<tr><td align=center>"
response.write "<table border=0 cellpadding=2 cellspacing=2 width=" & VB_TABLEWIDTH & " align=" & VB_TABLEALIGN & " hspace=10 vspace=10 bgcolor=" & VB_COLOR2 & ">"
response.write "<tr><td align=center bgcolor=" & VB_COLOR1 & "><font face=verdana size=1><b>Poll Results:<br />" & strQuestion & "</b></td></tr>"
intHighest = 0
do while not rst.EOF
if rst("vote") > intHighest then
intHighest = rst("vote")
end if
rst.moveNext
loop
rst.moveFirst
'Stepping throught the recordset.
'Each time, we determine the length of the bar, based on code chunk just before
do while not rst.EOF
if intHighest > VB_BARLENMAX then
intDivBy = intHighest/VB_BARLENMAX
intWidth = round((rst("vote")/intDivBy),0)
else
intMultBy = VB_BARLENMAX/(IntHighest+.0001)
'response.write intMarLenMax
'response.end
intWidth = round((rst("vote")*intMultBy),0)
end if
response.write "<tr><td align=left><font face=arial size=1>" & rst("answer") & "<br>"
if rst("vote") <> 0 then
response.write "<img src=" & VB_URL & "/images/bar_blue_left.gif height=8 width=1>"
response.write "<img src=" & VB_URL & "/images/bar_" & VB_BARCOLOR & ".jpg height=8 width=" & intWidth & ">"
response.write "<img src=" & VB_URL & "/images/bar_blue_left.gif height=8 width=1>"
response.write " " & rst("vote") & " (" & round(((rst("vote")/intTotal)*100),VB_DECPLACES) & "%)<br>"
else
response.write rst("vote") & " (0%)<br>"
'response.write "no votes<br />"
end if
response.write "<img src=" & VB_URL & "/images/bar_" & VB_BARCOLOR & ".jpg height=1 width=" & VB_TABLEWIDTH & ">"
response.write "</td></tr>"
rst.MoveNext
loop
response.write "</table></td></tr></table>"
rst.close
end sub
%>
<%
'This function makes the connection to your database.
'VB_STRCON is defined in the user variable include file.
function Connect()
set con=Server.CreateObject("ADODB.connection")
con.ConnectionString = VB_STRCON
con.open
set Connect = con
end function
%>
<%
' This sub verifies that a current session variable has not been emptied out.
' If it has, the session has ended due to a timeout or malformed URLs.
' The session state is checked at the start of each script in the 'admin' directory.
' You can modify the code here to redirect, or anything else you'd want.
sub CheckSession
if session("user") = "" then
%>
<center>
<font face="verdana" size="4" color="maroon">Tiden er løbet ud!</font><font face="verdana" size="4" color="maroon"><br />
<br />
<a href="vb_admin.asp">login</a> igen.</font>
</center><%
response.end
end if
end sub
%>
<%
sub UserMenu()
%>
<hr />
<font face="verdana" size="1"><b>
<a href="vb_admin.asp?func=control">Kontrolpanel</a> |
<a href="vb_admin.asp?func=edit">Lav ny afstemning</a> |
<a href="vb_admin.asp?func=user">Tilføj bruger</a> |
<a href="vb_admin.asp">Log af</a>
</b></font>
<hr />
<%
end sub
%>
