Just nu i M3-nätverket
Jump to content

vote.asp


Mats.

Recommended Posts

Jag har satt ihop en sida med en omröstningsfunktion. Nu finns det bara röst knappen att klicka på men jag vill komplettera med en knapp som visar resultatet av omröstningen. Någon kunnig som kan hjälpa mig med detta?

 

/Mats

 

 

<%

'Two varibles are passed into the db

'u_input is the value if the user entered a response to

'the vote/poll question....IP is the address of the user

u_input=request.form("u_input")

u_ip=request.servervariables("remote_addr")

 

' if the user did not enter anything in the poll on this visit

' then display the poll question and possible choices

if u_input = "" then

%>

<form method="post" action="<%= request.servervariables("script_name") %>">

<p>Test<br>

<input type="radio" value="1" name="u_input" >Yes<br>

<input type="radio" value="2" name="u_input">No<br>

<input type="submit" value="Submit" ></p>

</form>

<%

else

' if the user did input a choice on the vote/ballot

' check to see if their ip address is already in the db

' if the directory your .asp page is in does not have user

' write authority the accessdb variable and access db may

' need to be moved to your /cgi-bin/ directory and add that to the code below

accessdb="vote"

cn="driver={Microsoft Access Driver (*.mdb)};"

cn=cn & "dbq=" & server.mappath(accessdb)

set rs = server.createobject("ADODB.Recordset")

sql = "select ip from ballot where ip ='" & u_ip & "'"

 

rs.Open sql, cn

if rs.eof then

' if the user has not voted previously indicate it

been_here_before="No"

end if

rs.close

 

if been_here_before = "No" then

' Since the user has not voted previously their input

' their vote will be added to the db

sql = "insert into ballot (ip, selection" & u_input &") "

sql = sql & "values ('" & u_ip & "',1)"

rs.Open sql, cn

end if

 

'This will summerize and count the records in the db

sql= "select distinctrow "

sql= sql & "sum(selection1) as sum_selection1, "

sql= sql & "sum(selection2) as sum_selection2, "

sql= sql & "count(*) AS total_votes "

sql= sql & "FROM ballot;"

rs.Open sql, cn

 

total1=rs ("sum_selection1")

total2=rs ("sum_selection2")

count=rs ("total_votes") %>

 

Test<br>

<br>

<img src="green.jpg" height="10" width="<%= formatnumber((total1/count)*100,0) %>">&nbsp;

<%= formatnumber((total1/count)*100,1) %>%<br> Yes <br>

<img src="red.jpg" height="10" width="<%= formatnumber((total2/count)*100,0) %>">

<%= formatnumber((total2/count)*100,1) %> %<br> No <br>

Total Votes: <%= formatnumber(count,0,0) %><br> <% end if %>

<head>

<meta name="GENERATOR" content="Microsoft FrontPage 5.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title></title>

</head>

<body>

</body>

</html>

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...