zoukankan      html  css  js  c++  java
  • 简易投票软件示例

    表1:如图

    表2:如图

    显示界面:

    <style type="text/css">
    #fanhui{ display:none}
    </style>
    
    
    <form action="tpchuli.php" method="post">
    <?php
    
    $db = new  MySQLi("localhost","root","123","mydb");
    
    $sql = "select * from diaoyantimu";
    
    $result = $db->query($sql);
    
    $attr = $result->fetch_all();
    
    foreach($attr as $v)
    {
        echo "<div>{$v[1]}</div>";
        
        $sxx = "select * from diaoyanxuanxiang where timudaihao='{$v[0]}'";
        
        $rxx = $db->query($sxx);    
        $axx = $rxx->fetch_all();
        
        $bs = 0;
        if(!empty($_GET["a"]))
        {
            $bs = $_GET["a"];
        }
        
        $s = $bs==1?"none":"block";
        
        echo "<div id='toupiao' style='display:{$s}'>";
        foreach($axx as $v1)
        {
            echo "<div><input type='checkbox' name='tp[]' value='{$v1[0]}' />{$v1[1]}</div>";
        }
        echo "</div>";
        
        $s1 = $bs==0?"none":"block";
        
        //显示投票结果
        echo "<div id='jieguo' style='display:{$s1}'>";
        
        foreach($axx as $v2)
        {
            $v2[2]; //当前选项的人数
            //求总人数
            $szrs = "select sum(numbers) from diaoyanxuanxiang where timudaihao='{$v[0]}'";
            $rzrs = $db->query($szrs);
            $azrs = $rzrs->fetch_row();
            $azrs[0]; //总人数
            
            $bfb = ($v2[2]/$azrs[0])*100;
            
            echo "<div>{$v2[1]}<div style='100px; height:10px; border:1px solid black;'>
            <div style='{$bfb}%; height:10px; background-color:red'></div></div>{$v2[2]} {$bfb}%</div>"; } echo "</div>"; } ?> <input type="submit" value="投票" /> <input type="button" id="jg" value="查看结果" onclick="showjg()" /> <input type="button" id="fanhui" value="返回" onclick="showtp()" /> </form> </body> <script type="text/javascript"> function showjg() { document.getElementById("jieguo").style.display="block"; document.getElementById("toupiao").style.display="none"; document.getElementById("jg").style.display="none"; document.getElementById("fanhui").style.display="block"; } function showtp() { document.getElementById("jieguo").style.display="none"; document.getElementById("toupiao").style.display="block"; document.getElementById("jg").style.display="block"; document.getElementById("fanhui").style.display="none"; } </script>

    处理界面:

    <?php
    $attr = $_POST["tp"];
    
    $str = implode("','",$attr);
    
    $sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids in('{$str}')";
    
    $db = new MySQLi("localhost","root","123","mydb");
    $db->query($sql);
    
    header("location:toupiao.php?a=1");
  • 相关阅读:
    自己写的一个校验IP、IP掩码、IP段的方法
    JS 数组方法splice的源码探究
    element ui 的时间选择控件
    浅谈闭包
    tensorFlow-深度学习训练并行模式
    tensorflow-TensorBoard
    tensorflow-RNN和LSTM
    tensorflow-TFRecord报错ValueError: Protocol message Feature has no "feature" field.
    tensorflow-mnist报错[WinError 10060] 由于连接方在一段时间后没有正确答复解决办法
    旋转图片,增加神经网络的准确率
  • 原文地址:https://www.cnblogs.com/u1020641/p/6027009.html
Copyright © 2011-2022 走看看