投票的選擇的不確定性常常使我們在設(shè)計數(shù)據(jù)庫的時候感到無從下手。所以我用的不是數(shù)據(jù)庫保存的投票選項而是用的xml。用xml的設(shè)計的好處有很多,其中包括我們可以在其中保留很多的屬性,在設(shè)計的時候,也可以進行多重選擇都是一個很好的辦法,用xsl對生成的xml文件進行解析這樣的設(shè)計模式感覺很爽
我的xml的sample是這樣的
<?xml version=‘1.0‘ encoding=‘gb2312‘ ?>
<?xml-stylesheet type=‘text/xsl‘ href=‘votesample.xsl‘?>
<root>
<Questionname><![CDATA[我們的網(wǎng)站好看么?]]></Questionname>
<Choose select=‘radio‘ votekindid=‘1‘>
<ChooseItem value=‘a(chǎn)‘><![CDATA[好看]]></ChooseItem>
<ChooseItem value=‘b‘><![CDATA[不好看]]></ChooseItem>
<ChooseItem value=‘c‘><![CDATA[不知道]]></ChooseItem>
<ChooseItem value=‘d‘><![CDATA[無所謂]]></ChooseItem>
</Choose>
</root>
xsl的sample:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="<xsl:output method="xml" indent="yes" encoding="GB2312" />
<xsl:template match="/">
<div>
<div><xsl:value-of select="http://root/Questionname" /></div>
<table width="95%">
<xsl:variable name="inputelement" select="//root/Choose/@select" />
<form action="vote/record.asp" target="observe" method="post">
<input type="hidden" name="votekindid" value="{//root/Choose/@votekindid}" />
<xsl:for-each select="http://root/Choose/ChooseItem">
<tr>
<td align="left"><input type="{$inputelement}" name="choise" value="{@value}"><xsl:if test="position()=1"><xsl:attribute name="checked">checked</xsl:attribute></xsl:if></input><xsl:value-of select="@value" /></td><td align="left" width="80%"><xsl:value-of select="." /></td>
</tr>
</xsl:for-each>
<tr><td align="center"></td><td align="left"><img src="images/index_left_button3.gif" onclick="javascript:newWin(‘vote/result.asp?votekindid={//root/Choose/@votekindid}‘)" style="cursor:hand;" /> <input type="image" src="images/index_left_button4.gif" value="提交" onclick="javascript:newWin()" /></td></tr>
</form>
</table>
</div>
<script language="javascript">
<![CDATA[
function newWin(url){
if(url==‘‘){
newWindow=window.open("about:blank","observe","toolbar,resizable,scrollbars,dependent,width=500,height=420,left=150,top=80");
newWindow.focus();}
else{
newWindow=window.open(url,"observe","toolbar,resizable,scrollbars,dependent,width=500,height=420,left=150,top=80");
newWindow.focus();
}
}
]]>
</script>
</xsl:template>
</xsl:stylesheet>
然后用一個vote表,記錄一下值
用一個sql語句 select votechoose,count(votechoose) from vote where voteid=值 group by votechoose 進行統(tǒng)計