对DeDecms自带的调查投票模型不大喜欢,自己弄了个新模型,把过程写写,供大家参考:
1 新建模型 名字自己看着起,字段如下
2 建立一个栏目 模型选择刚才建立的模型
3 添加投票 投票选项中每行是一个选项,投票项和得票数使用|分割
其中自己写了两个文件:
/plus/YfVote.php
<?php 
require(dirname(__FILE__)."/../include/common.inc.php");
$aid=(int)$_GET['id'];
$aid = (isset($aid) && is_numeric($aid)) ? $aid : 0;
if($aid==0) die(" Request Error! ");
?>
document.write(" <div class=\"indagate\"> <script language=\"javascript\">$(function(){$(\".hoverClass\").hover(function(){$(this).addClass(\"hover\");},function(){$(this).removeClass(\"hover\");});})  </script>");
<?php
$sql = "Select *  FROM `dede_addondswindvote` where aid=".$aid;
$row = $dsql->GetOne($sql);
$dsql->Close(); 
?>
document.write("<p><a href=\"/plus/view.php?aid=<?php echo $aid?>\"; target=\"_blank\"><?php echo str_replace("\r\n","",$row['shuoming'])?><br /></a></p><form action=\"/plus/YFvotesave.php?voteid=<?php echo $aid?>\" method=\"post\" name=\"voteform\" target=\"_blank\">  <ul>");
<?php
$vote=explode("\r\n",$row['xuanxiang']);
$allVoter=0;
$voteItem= array();
$voteItemR= array();
foreach($vote as $key => $v)
{
$voteList=explode("|",$v);
$voteItem[$key]=$voteList[0];
$voteItemR[$key]=$voteList[1];
$allVoter=$allVoter+$voteList[1];
}
foreach($vote as $key => $v)
{
$voteList=explode("|",$v);
$Bl=round(($voteList[1]/$allVoter)*100,2);
if($voteItem[$key]!="")
{
?>
document.write("<li class=\"hoverClass\" title=\"点击选项投票\" onClick=\"document.getElementById(\'votevalue\').value=<?php echo $key?>;voteform.submit();\"><div class=\"scale\" title=\"比例:<?php echo $Bl?>%\"><span style=\"width:<?php echo $Bl?>%\"></span></div><div class=\"value\"><?php echo $voteItem[$key]?><span><?php echo $Bl?>%</span></div></li>");
<?php
}}
?>
document.write("<input type=\"hidden\" id=\"votevalue\" name=\"votedata\" value=\"\" />  <input type=\"hidden\" value=\"提交\" name=\"dosubmit\" /><input type=\"hidden\" value=\&quot;#\&quot; name=\"forward\" />  </ul></form>  <div class=\"indagate_bt\"><a href=\"/plus/view.php?aid=<?php echo $aid?>\"; target=\"_blank\"><img src=\"/images/indagate_bt.gif\" title=\"参与讨论\" /></a>已有(<?php echo $allVoter?>)人参与投票</div>");
<?php
 $sql2 = "Select *  FROM `dede_addondswindvote` where aid<>".$aid." order by aid desc limit 0,5";
 $dsql->SetQuery($sql2);
 $dsql->Execute();
 while($row2 = $dsql->GetArray())
{
?>
document.write("<p class=\"iother\"><span></span><?php echo $row2['shuoming']?><a href=\"/plus/view.php?aid=<?php echo $row2['aid']?>\"; target=\"_blank\">我来投票</a></p></div>");
<?php

?>
/plus/YFvotesave.php
<?php
require(dirname(__FILE__)."/../include/common.inc.php");
$aid=(int)$_GET['voteid'];
$vid=(int)$_POST['votedata'];
$aid = (isset($aid) && is_numeric($aid)) ? $aid : 0;
if($aid==0) die(" Request Error! ");
?>
<?php
$sql = "Select *  FROM `dede_addondswindvote` where aid=".$aid;
$row = $dsql->GetOne($sql);
$dsql->Close(); 
?>
<?php
$vote=explode("\r\n",$row['xuanxiang']);
$voteItem= array();
$voteItemR= array();
foreach($vote as $key => $v)
{
$voteList=explode("|",$v);
$voteItem[$key]=$voteList[0];
$voteItemR[$key]=$voteList[1];
}
$voteItemR[$vid]=$voteItemR[$vid]+1;
$voteSave="";
foreach($vote as $key => $v)
{
if($voteItem[$key]!="")
{
$voteSave=$voteSave.$voteItem[$key]."|".$voteItemR[$key]."<br>";
}}
$voteSave=trim($voteSave);
$voteSave=preg_replace("'([\r\n])[\s]+'", "", $voteSave);
$voteSave=str_replace("<br>","\r\n",$voteSave);
$sql2 = "update `dede_addondswindvote` set xuanxiang='".$voteSave."' where aid=".$aid;
$dsql->SetQuery($sql2);
$dsql->Execute();
echo "投票成功,网页3秒后自动关闭"
?>
<body
<script>
function mm()
{
    window.opener=null;
    window.close();
}
</script>
</body>