注册 登录
编程论坛 ASP技术论坛

在同一个字段中如何存放和读取数组

yanziyz 发布于 2008-06-17 10:06, 1266 次点击
大家好,我要作一个问卷调查系统,存放问题选项,
例如:
问题:你对英语感兴趣吗?
答案:1、特别感兴趣
      2、比较感兴趣
      3、不太感兴趣  
      4、一点也不感兴趣

而在数据库中把答案存放Question_answer字段:特别感兴趣&比较感兴趣&不太感兴趣&一点也不感兴趣

有人提示我用数组的方式读取和存放,但我自己不知道具体怎么实现,请高手指教,急,多谢了!
7 回复
#2
hmhz2008-06-17 10:24
字段里一个问题只有一个答案,要使用什么数组?
你这个不是单选吗?
#3
hmhz2008-06-17 10:31
程序代码:


<%
Set rs=server.createobject("adodb.recordset")
rs.open "select Sex from dbo.Contact",conn,1,1
if not(rs.eof and rs.bof) then
Sex=split(rs("Sex"),"&")
end if
rs.close
set rs=nothing
%>

<table border="1" width="30%" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#C0C0C0">
<form name="myform" method="post">
<tr>
    <td width="10%" align="right">问题:</td>
    <td width="20%">你对英语感兴趣吗?</td>
</tr>
<tr>
    <td align="right">答案:</td>
    <td>
<%for i=0 to ubound(Sex)%>
    <input type="radio" name="Sex" value="<%=i%>" /><%=Sex(i)%><br>
<%next%>
    </td>
</tr>
</form>
</table>
#4
yanziyz2008-06-17 10:34
我是要动态生成问卷,需对所有选项进行存储,最后又要动态显示问卷,谢谢版主关注
#5
yanziyz2008-06-17 10:42
谢谢了,版主太厉害了,一语惊人!这是读取,存储的时候该如何。。。还劳烦版主给指点一下,多谢了,
#6
hmhz2008-06-17 12:32
程序代码:
添加代码:
<%
if request.form("Submit")="添加" then
wenti=request.form("wenti")
Sex1=request.form("Sex1")
Sex2=request.form("Sex2")
Sex3=request.form("Sex3")
Sex4=request.form("Sex4")
abc=wenti&"&"&Sex1&"&"&Sex1&"&"&Sex2&"&Sex3&"&Sex4
conn.Execute "insert into answer(Question_answer) values('"&abc&"')"
end if
%>

<table border="1" width="30%" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#C0C0C0">
<form name="myform" method="post">
<tr>
<td width="10%" align="right">问题:</td>
<td width="20%"><input type="text" name="wenti" value="你对英语感兴趣吗?" /></td>
</tr>
<tr>
<td align="right">答案:</td>
<td><input type="text" name="Sex1" value="特别感兴趣" /><br>
<input type="text" name="Sex2" value="比较感兴趣" /><br>
<input type="text" name="Sex3" value="不太感兴趣" /><br>
<input type="text" name="Sex4" value="一点也不感兴趣" />
</td>
</tr>
<tr align="center"><td colspan="2"><input type="Submit" name="Submit" value="添加" /></td></tr>
</form>
</table>




读取代码:
<%
Set rs=server.createobject("adodb.recordset")
rs.open "select Question_answer from dbo.answer",conn,1,1
if not(rs.eof and rs.bof) then
Sex=split(rs("Question_answer"),"&")
end if
rs.close
set rs=nothing
%>

<table border="1" width="30%" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="#C0C0C0">
<form name="myform" method="post">
<tr>
<td width="10%" align="right">问题:</td>
<td width="20%"><%=Sex(0)%></td>
</tr>
<tr>
<td align="right">答案:</td>
<td>
<%for i=1 to ubound(Sex)%>
<input type="radio" name="Sex" value="<%=i%>" /><%=Sex(i)%><br>
<%next%>
</td>
</tr>
</form>
</table>
#7
yanziyz2008-06-19 11:33
谢谢版主hmhz,你的提示对我作这个系统的帮助很大。
但还有问题,希望提示我:

问卷的题型有5种,
单选题| 多选题| 带文字输入的单选题| 带文字输入的多选题| 问答题

我如何实现选中不同题型,下面就出现相应题型的表单,供录入问卷调查,

我考虑部分代码是:
请选择题目类型:单选题<input name="Question_type" type="radio" value="1" onClick="">
| 多选题<input name="Question_type" type="radio" value="2" onClick="">
|  带文字输入的单选题<input name="Question_type" type="radio" value="3" onClick="">
| 带文字输入的多选题<input name="Question_type" type="radio" value="4" onClick=;">
|  问答题<input name="Question_type" type="radio" value="5" onClick="">
但onClick里面怎么写就不知道了。

高手提示一下,谢谢,不胜感激!
#8
yanziyz2008-06-19 17:26
高手出门了吗,怎么都不回复,用ajax实现怎么样啊,懂得指点一下
1