投票操作管理系统

vote.php
<html>
<head>
    <meta charset="utf-8">
    <title>vote</title>
    <script>
        function getVote(int) {
            xmlhttp=new XMLHttpRequest();
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    document.getElementById("poll").innerHTML=xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET","poll_vote.php?vote="+int,true);
            xmlhttp.send();
        }
    </script>
</head>
<body>
<div id="poll">
    <form>
        菊花侠:
        <input type="radio" name="vote" value="0" οnclick="getVote(this.value)">
        <br>桃花怪:
        <input type="radio" name="vote" value="1" οnclick="getVote(this.value)">
    </form>
</div>
</body>
</html>

poll_vote.php
<?php
header("Content-type:text/html;charset=utf-8");
$vote = htmlspecialchars($_REQUEST['vote']);

// 获取文件中存储的数据
$fileDir = "poll_result.txt";
$content = file_get_contents($fileDir);


// 将数据分割到数组中
$array = explode("||", $content);
$yes = $array[0];
$no = $array[1];

if ($vote == 0)
{
    $yes+=1;
}

if ($vote == 1)
{
    $no+=1;
}

// 插入投票数据
$insertvote = $yes."||".$no;
$fp = fopen($fileDir,"w");
fputs($fp,$insertvote);
fclose($fp);
?>

<h2>投票结果:</h2>
<table>
    <tr>
        <td>菊花侠:</td>
        <td>
  <span style="display: inline-block; background-color:green;
      width:<?php echo(100*round($yes/($no+$yes),2)); ?>px;
      height:20px;" ></span>
            <?php echo(100*round($yes/($no+$yes),2)); ?>%
        </td>
    </tr>
    <tr>
        <td>桃花怪:</td>
        <td>
  <span style="display: inline-block; background-color:red;
      width:<?php echo(100*round($no/($no+$yes),2)); ?>px;
      height:20px;"></span>
            <?php echo(100*round($no/($no+$yes),2)); ?>%
        </td>
    </tr>
</table>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值