投票的结果页面的功能是根据投票的统计数据,显示当前的投票结果。这种功能插件一旦实现,到处可用。现在我们直接看代码,看看是如何实现的!
数据库链连接部分代码就不用上了吧,直接写一下就好了,然后在其他页面include_once()
<?PHP
if($ouser==''){
echo"<script>alert('请先登录!');location.href='index.PHP';</script>";
}else{
$Voteid=@$_GET['vid'];
if($Voteid==''){
echo"location.href='index.PHP';</script>";
}else{
$sql="selectvname,starttime,uid,vintro,open,more,max,minfromVotewherevid='".$Voteid."'";
$vitem=MysqL_fetch_array($Voteitem);
$sql2="SELECTitemcount,item,numFROMVotetitlewherevid='".$Voteid."'";
$Votetitle=MysqL_query($sql2);
$vtitle=MysqL_fetch_array($Votetitle);
$sql3="SELECTusernameFROMuserswhereuid='".$vitem['uid']."'";
$username=MysqL_fetch_row($uname);
}
}
?>投票页面的基本信息
<center><h2><?PHPecho$vitem['vname'];?></h2></center>
<divid="Vote">
<table>
<tr>
<td>发布人:<?PHPecho$username[0];?></td><td>发布时间:<?PHPecho$vitem['starttime'];?></td>
</tr>
</table>
<divid="Vote_intro">
<?PHPecho$vitem['vintro']?>
</div>
<divid="Vote_contend">假如你投票的项目不止一项,这里做简单的实现了逐条输出结果
<?PHP
$itemcount=$vtitle['itemcount'];
$option=explode('*',$vtitle['item']);
$ballot=explode('*',$vtitle['num']);
$total=0;
$rate;
$ratewidth;
for($i=0;$i<count($ballot);$i++){
$total=$total+$ballot[$i];
}
for($i=0;$i<count($ballot);$i++){
if($total==0){
$rate[$i]=0;
$ratewidth[$i]=0;
}else{
$rate[$i]=round(($ballot[$i]/$total)*100);
$ratewidth[$i]=$rate[$i]*2;
}
}
for($i=0;$i<$itemcount;$i++){
echo"<divclass='Vote_contend_item'>".$option[$i]."</div>".
"<divclass='Vote_contend_img'><divclass='Vote_contend_strip''width:".$ratewidth[$i]."px'></div></div>".
"<div class='Vote_contend_count'>票数:".$ballot[$i]."得票率:".$rate[$i]."%</div>";
}
?>计算出投票率,可通过css做成图表,图形等
for($i=0;$i<count($ballot);$i++){
$total=$total+$ballot[$i];
}
for($i=0;$i<count($ballot);$i++){
if($total==0){
$rate[$i]=0;
$ratewidth[$i]=0;
}else{
$rate[$i]=round(($ballot[$i]/$total)*100);
$ratewidth[$i]=$rate[$i]*2;
}
}
效果图,很明显这是一个很简单的投票功能,还有待进一步去完善。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。