img elife


发表于2000/8/18 15:11:00  551人阅读

1. vote.asp

<%Response.Buffer = True%>

<!-- #INCLUDE FILE="adovbs.inc" -->

'*** Remember to create those variables before trying to use them.

    Dim objConn    
    Dim objRec3
    Dim strConnect
    Dim    varTopic, varTopicID, varSelectionNum, varSelected
    Dim i, varTotal, varThis, varThisTitle, varAlreadyVote

    strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("vote.mdb") & ";DefaultDir=" & Server.MapPath(".") & ";DriverId=25;FILE=MS Access;MaxBufferSize=512;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;;User Id=admin;"
    Set objConn = Server.CreateObject ("ADODB.Connection")     '*** Create an ADO database connection object.
    Set objRec3 = Server.CreateObject ("ADODB.Recordset")     '** Create an ADO RecordSet object.
    objConn.Open strConnect    '*** Open the connection to the database
    objRec3.Open "vote", objConn, adOpenForwardOnly, adLockPessimistic, adUseServer '*** Open the recordset

    varTopic = Request.Form("topic")
    varTopicID = Request.Form("topicID")
    if varTopicID="" then
        varTopicID = Request.QueryString("topicID")
    end if
    varSelectionNum = Request.Form("selectionNum")
    varSelected = Request.Form("selected")

    objRec3.Filter = 0
    objRec3.Filter = "topicID=" & varTopicID    'only number can be filter?
    If NOT objRec3.EOF then
        if Request.Form("selected") = "" then
            varAlreadyVote="alreadyVote" & "_" & varTopicID
            if Session(varAlreadyVote)<>"true" then
                objRec3("selection" & varSelected & "_count") = objRec3("selection" & varSelected & "_count") +1
            end if
        end if
        for i=0 to objRec3("selectionNum")-1
            varTotal=varTotal+ objRec3("selection" & i & "_count")

<p align=left>    <% =varTopic %> </p>
<p align=center>
<table width=480 border=0 cellspacing=0 cellpadding=0 bgcolor=#000000>
<caption align=left><font size=2>共有 <font color=red><% =varTotal %></font>人参加</font></caption>
<table width=480 border=0 cellspacing=1 cellpadding=3>
    <tr bgcolor=#dcdcdc align=center valign=center>
        <th width=120><font size=2>选项</font></td>
        <th width=300><font size=2>比  例</font></td>
        <th width=60><font size=2>人数</font></td>

        for i=0 to objRec3("selectionNum")-1
            varThisTitle=objRec3("selection" & i & "_title")
            varThis=objRec3("selection" & i & "_count")
<tr bgcolor=#ffffff valign=center>
<td width=120 align=center><font size=2 color=#ff0000><% =varThisTitle %></font></td>
<td width=300 align=left><img src="color.gif" width=<% =varThis*100/varTotal %> height=12 border=0><font size=2 color=#ff0000>
    <% = left(varThis*100/varTotal, 5) %>%
<td width=60 align=center><font size=2 color=#ff0000><% =varThis %></font></td>


    else    'no this topic yet

        objRec3("topicID") = varTopicID
        objRec3("topic") = varTopic
        objRec3("selectionNum") = varSelectionNum

        for i=0 to varSelectionNum
            objRec3("selection" & i & "_title") = Request.Form("selection" & i & "_title")

        response.write "added"
    End If


    Set objRec3 = Nothing
    Set objConn = Nothing    

2. vote.htm



<script language="JavaScript">
function newswindow(url)



    <form method="post" action="vote.asp" onSubmit="windowOpener('')" target="new">
    <td width=80>
        <input type="radio" name="selected" value="0" style="background-color:rgb(255,205,96)">比较混乱<br>
        <input type="radio" name="selected" value="1" style="background-color:rgb(255,205,96)">马马虎虎<br>
        <input type="radio" name="selected" value="2" style="background-color:rgb(255,205,96)">秩序井然
    <td width=55>
        <input type=hidden name=topicID value=1>
        <input type=hidden name=topic value=您认为'你说我说'栏目>
        <input type=hidden name=selectionNum value=3>
        <input type=hidden name=selection0_title value=比较混乱>
        <input type=hidden name=selection1_title value=马马虎虎>
        <input type=hidden name=selection2_title value=秩序井然>
        <input type="button" value="查看" style="background-color:rgb(255,205,96)" onClick=newswindow("vote.asp?topicID=1") target=new>
        <input type=submit value="提交" style="background-color:rgb(255,205,96)">



3. vote.mdb
a Access database file, there is a table named "vote"
topicID topic selectionNum selection0_title selection0_count ...

0 0



取 消