zoukankan      html  css  js  c++  java
  • 5月8日 例:投票

    根据条件建立相关数据库和表,通过选项造成相关条形图的比例变化

    从数据库中得到数据后,对数据进行处理,数据的关联性较强

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    
    <style type="text/css">
    #list{ 250px; height:200px}
    #jieguo{250px; height:200px}
    .x{float:left}
    </style>
    </head>
    
    <body>
    <form action="chuli.php" method="post">
    <?php
    include("../DBDA.class.php");
    $db = new DBDA();
    
    $sql = "select * from diaoyantimu limit 0,1";
    
    $attr = $db->Query($sql);
    
    $tmmc = $attr[0][1];
    $tmdh = $attr[0][0];
    echo "<div>题目名称:{$tmmc}</div>";
    $sqlxx = "select * from diaoyanxuanxiang where timudaihao ='{$tmdh}'";
    $attrxx = $db->Query($sqlxx);
    echo "<div id='list'>";
    foreach($attrxx as $v)
    {
        echo "<div><input type='checkbox' value='{$v[0]}' name='xx[]' />
        <span>{$v[1]}</span>
        </div>";
        
    }
    
    
    ?>
    <input type="submit" value="提交"/>
    <input type="button" value="查看结果" id="check" onclick="Showjieguo()"/>
    </form>
    </div>
    <div id="jieguo" style="display:none">
    <?php
    $sqlsum = "select sum(Numbers) from diaoyanxuanxiang where 
    timudaihao = '{$tmdh}'";
    $attrsum = $db->Query($sqlsum);//所有人数
    
    
    foreach($attrxx as $v)
    {
        $name = $v[1];//选项名
        $number = $v[2];//选择该项的人数
        $bfb = ($number/$attrsum[0][0])*100;
        $bfb = round($bfb,2);
        
        echo "<div style='250px; height:30px'>
        <span class='x'>{$name}</span>
        <div class='x' style='100px; height:8px; border:1px solid red'>
        <div style='{$bfb}%; height:8px; background-color:red'></div>
        
        </div>
        <span class='x'>{$number}&nbsp;</span>
        <span class='x'>{$bfb}%</span>
        </div>";
    }
    ?>
    <input type="button" value="返回" id="fanhui" onclick="Showlost()"/>
    </div>
    <script type="text/javascript">
    function Showjieguo()
    {
        document.getElementById("list").style.display = "none";
        document.getElementById("jieguo").style.display = "block";
    }
    function Showlist()
    {
        document.getElementById("list").style.display = "block";
        document.getElementById("jieguo").style.display = "none";
    }
    </script>
    </body>

    数据处理页面:

    <?php
    
    $attr = $_POST["xx"];
    
    include("../DBDA.class.php");
    $db = new DBDA();
    foreach($attr as $v)
    {
        $sql = "update diaoyanxuanxiang set Numbers = Numbers+1
        where Ids = '{$v}'";
        $db->Query($sql,1);
    }
    header("location:toupiao.php");
  • 相关阅读:
    视频编码之释——从H.261 到H.264
    bitmap图像介绍
    用搜索引擎搜索我的名字 @_@
    blog标题由来
    ORACLE双机热备安装及物理迁移 for win2000
    审核再次失败
    asp.net学习历程
    痛并快乐着
    开心,blog点击率超过1000
    XP下ASP.NET不能访问ORACLE数据库的解决方案
  • 原文地址:https://www.cnblogs.com/dongqiaozhi/p/5472240.html
Copyright © 2011-2022 走看看