Program | vote
In order to investigate the site visitors to the position of the specific issues, we can set up a polling program in the site, site visitors directly select the answer, the program automatically to all the answers to statistics and display.
The following is a simple flash version of the voting program, the background using xml+ asp+ MySQL: Because most web workers are familiar with ASP, XML can simplify complex problems, the reason for using MySQL is that access I did not install, the program does not need any stored procedures, So no need to move SQL Server, Oracle and other heavy weapons.
Click here to download the source file (53k)
Problem Analysis : This voting procedure is the choice question, therefore we use a field to store the user's answer.
create databases and tables : Table names and database names are arbitrary, and fields are defined as follows:
Voteid unsigned integer autonumber
Result short integer storage user Select this program range in 0-2
Userip Char (25) User IP address actual length 21
Message char (255) Append//This program is not used
Create using Mysql-front, as shown in the following illustration:
Design The Flash user interface : Drag three RadioButton from the Window/components/flash UI components to the stage,
Set the label, others as the default value. (Can be set from both the property panel and the component parameters panel)
Here you will use a Chart component (subtype in the HTML UI components), and you can Www.macromedia.com/exchange/flash the download to the MM extension resource.
The parameters are set as follows:
Flash end of the program is very simple only three lines:
In the first frame of the timeline, add the following code
The tag name is "Start voting!" button, the event handle is Sendvote, and after clicking, execute the following custom function
function Sendvote () {
_root.mytb.readdata ("http://localhost/votexml.asp?selectresult=" +radiogroup.getinstance ());
}
Server-side program to write, you may see a votexml.asp file, below we will build it.
The code is as follows:
<% @LANGUAGE = "VBSCRIPT" codepage= "936"%>
<%
Set Conn=server. CreateObject ("Adodb.connection")
Conn.Open "Dsn=mysql"
Set Rec=server. CreateObject ("Adodb.recordset")
%>
<% If Request ("Selectresult") <> "" Then
userip= Request.ServerVariables ("REMOTE_ADDR")
Selectresult=request. QueryString ("Selectresult")
Rec.open "SELECT COUNT (*) as Count from votetable where votedate> '" &now () -0.125 & "' and userip= '" &USERIP&A MP; "'", Conn
If Rec ("Count") >0 Then
Bzh= "Repeat ballot invalid"
Rec.close
' Response. Write ("Please do not repeat the vote")
Else
Rec.close
Bzh= "Vote valid"
Conn.execute "INSERT into votetable (Userip,result) VALUES (' &userip& '," & selectresult& ")"
End If
Else
Bzh= "View Polls"
End If
Rec.open "SELECT result,count (*) as Count from votetable GROUP by result ASC", Conn
T0=cint (Rec ("Count")
Rec.movenext
T1=cint (Rec ("Count")
Rec.movenext
T2=cint (Rec ("Count")
Tcount=t0+t1+t2
Response.contenttype= "Text/xml"
%>
<% Response.Write "<?xml version= ' 1.0 ' encoding= ' gb2312 '?> '"
Response. Write ("<root bz= '" &bzh& "' >")
Response.Write "<base><data value= ' believes in ' color= ' 0xff00cc '/><data value= ' don't Believe ' color= ' 0x0000CC '"/>< Data value= ' It's not clear ' color= ' 0x00cc00 '/></base> '
Response. Write ("<record value= '" &tcount& "Ticket ' color= ' 0x0000cc ' >")
Response. Write ("<data value= '" &t0/tcount& "'/>")
Response. Write ("<data value= '" &t1/tcount& "'/>")
Response. Write ("<data value= '" &t2/tcount& "'/></record>")
%>
<%
Response.Write "</root>"
Rec.close
Set rec=nothing
Conn.close
Set conn=nothing
%>
Save the file as votexml.asp, and place it in the directory where the Web path is "/".
Note: When actually applied to a Web server, use a relative path in Flash. Flash movie and votexml.asp can be placed in any directory.