多用户投票系统

作者:vkvi 来源:ITPOW 日期:2002-8-8
  两个表,一个是vote1,一个是vote2(洋文太差,找不出合适的名称,暂时加1,2区别吧。)
=====
vote1
    id            区分哪个用户的
    title         要调查的问题
    multiSelect   是否允许多选
=====
vote2
    id
    voteID        指向vote1的ID
    optionTitle   问题选项,即要访问者选择的项
    optionCount   代表选择此选项的人(次)数
=========================================
<%option explicit%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>投票</title>
</head>

<body>
<!--#include file="conn.asp"-->
<%
dim sql,rs,rs1
set rs=Server.CreateObject("ADODB.RecordSet")
set rs1=Server.CreateObject("ADODB.RecordSet")
%>
<div align="center">
  <center>
<form action="process.asp" method="post">
  <table border="0" width="760" height="46" cellspacing="1">
  <%
  sql="select * from vote1"
  rs.open sql,cn,1,1
  dim id,multiSelect,i
  do while not rs.eof
    id=cLng(rs("id"))
    multiSelect=rs("multiSelect")
    i=i+1
  %>
    <tr>
      <td width="646" height="17" colspan="2"><%=i%>、<%=rs("title")%></td>
    </tr>
    <tr>
      <td width="23" height="8" valign="top"></td>
      <td width="730" height="8">
      <table border="0" cellspacing="1" width="100%">
        <%
        sql="select * from vote2 where voteID="&id
        rs1.open sql,cn,1,1
        do while not rs1.eof
        %>
        <tr>
          <td width="100%">
            <%
            if multiSelect then
              response.write("<input type=checkBox name="&rs("id")&" value="&rs1("id")&">")//多选,name为投票ID,value为选项ID
            else
              response.write("<input type=radio name="&rs("id")&" value="&rs1("id")&">")/////////单选,name为投票ID,value为选项ID
            end if
            response.write(rs1("optionTitle"))
            %>
          </td>
        </tr>
        <%            
          rs1.moveNext
        loop
        rs1.close
        %>
      </table>
      </td>
    </tr>
    <tr>
      <td width="646" height="12" colspan="2"></td>
    </tr>
  <%
    rs.moveNext
  loop
  rs.close
  %>
    <tr>
      <td width="646" height="12" colspan="2">
      <input type="submit" value="Submit" name="B1"></td>
    </tr>
  </table>
</form>
  </center>
</div>
<%
set rs=nothing
set rs1=nothing
cn.close
set cn=nothing
%>
</body>

</html>
=========================================
处理就比较简单了,显示结果和这个差不多,所以就省略了。
   
相关文章