在同一个字段中如何存放和读取数组
大家好,我要作一个问卷调查系统,存放问题选项,例如:
问题:你对英语感兴趣吗?
答案:1、特别感兴趣
2、比较感兴趣
3、不太感兴趣
4、一点也不感兴趣
而在数据库中把答案存放Question_answer字段:特别感兴趣&比较感兴趣&不太感兴趣&一点也不感兴趣
有人提示我用数组的方式读取和存放,但我自己不知道具体怎么实现,请高手指教,急,多谢了!
<% 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>
添加代码: <% 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>