zoukankan      html  css  js  c++  java
  • PHP——投票

    要求:

    选择第一个页面的复选框值,点击提交则提交数据,点击查看结果在同一页面覆盖显示结果的投票人数,百分比和进度条,点击返回,返回第一页面

    数据库为 投票

    表格为diaoyanxx

    表格内容为:

    zhuye.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    * 
    {
        margin:0px;
        padding:0px;
        }
    h3
    {
        margin:10px;
        }    
    .diyiceng
    {
        height:220px;
        width:200px;
        background-color:#0F6;
        position:absolute;
        visibility:visible;
        left:10px;
        top:40px;
        }
    .dierceng
    {
        height:220px;
        width:800px;
        background-color:#6FC;
        position:absolute;
        visibility:hidden;
        left:0px;
        top:0px;
        }
    .xuanxiang
    {
        position:absolute;
        }
    .jindu
    {
        width:200px;
        height:10px;
        position:absolute;
        left:100px;
        border:solid #999 1px;
        }
    .jindutiao
    {
        
        height:8px;
        position:absolute;
        background-color:#0F0;
        border:solid 1px #00FF00;
        }
    .shuzi
    {
        position:absolute;
        left:320px;
        }
    .baifenbi
    {
        position:absolute;
        left:350px;
        }            
    </style>
    </head>
    
    <body>
    
    <h3>你35岁的发展方向?</h3>
    
    <div class="diyiceng" id="diyiceng">
    <form action="xiugai.php" method="post">
    <?php
    
        $db=new mysqli("localhost","root","123","投票");
        if(mysqli_connect_error())
        {
            echo "连接错误";
            }
        else
        {
            $sql="select * from diaoyanxx";
            $resulttp=$db->query($sql);
            
            while($row = $resulttp->fetch_row())
            {
                echo "<div><input type='checkbox' name='test[]' value='".$row[0]."'/>".$row[1]."</div><br />";
            }
            
        }
    
    ?>
    
    
    <input type="submit" name="submit" value="提交" />&nbsp;&nbsp;<input type="button" name="chakan" value="查看结果" onclick="xianshi()"/>
    </form>
    <?php
    $db=new mysqli("localhost","root","123","投票");
    if(mysqli_connect_error())
    {
        echo "连接错误";
        }
    else
    {
        $sql="select * from diaoyanxx";
        $result=$db->query($sql);
        
    echo "<div class='dierceng' id='yincang'>";
    echo "<form>";
    
        $sqlsum = "select SUM(numbers) from diaoyanxx";
        $resultsum = $db->query($sqlsum);
        $aa = $resultsum->fetch_row();
        $zongshu = $aa[0];
    
        while($rowjg = $result->fetch_row())
        {
            $xuanxiang = $rowjg[1];
            $shuliang = $rowjg[2];
            $baifenbi = $shuliang/$zongshu*100;
            $baifenbi1=round($baifenbi,1);//对小数取一位
            
            echo "<div><div class='xuanxiang'>".$xuanxiang."</div><div class='jindu'><div class='jindutiao' style='".$baifenbi."%'></div></div><div class='shuzi'>".$shuliang."</div><div class='baifenbi'>".$baifenbi1."%</div></div><br /><br />";
        }
    
    echo "<input type='button' name='fanhui' value='返回' onclick='buxianshi()' />";
    echo "</form>";
    echo "</div></div>";
        
    }
    ?>
    </body>
    </html>
    <script>
    function xianshi()
    {
       var a=document.getElementById("yincang");
       if(a.style.visibility="hidden")
       {
           a.style.visibility="visible";
       }
      
    }
    function buxianshi()
    {
       var a=document.getElementById("yincang");
       if(a.style.visibility="visible")
       {
           a.style.visibility="hidden";
       }
      
    }
     
    </script>

    xiugai.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <?php
    $test=$_POST["test"];
    
        
    //1.造连接对象
    $db=new mysqli("localhost","root","123","投票");
    //2.判断是否连接成功
    if(mysqli_connect_error())
    {
        echo "连接失败";
        }
        else
        {
            for($i=0;$i<count($test);$i++)
          {
            $sql="update diaoyanxx set numbers=numbers+1 where ids='".$test[$i]."'";
            
            $result=$db->query($sql);
            
          }
           
        
            //判断是否修改成功
            if($result)
            {
                header("Location:zhuye.php");
                }
                else
                {
                    echo "修改失败!";
                    }
            
            }
    
    ?>
    </body>
    </html>
  • 相关阅读:
    《linux/unix设计思想》读后感
    webserver ZooKeeper Cluster
    OS + RedHat 6.3 x64 / sshd X11 /
    nGrinder SocketTest.groovy
    OS + Centos7.6 gdm / xmanager xstart
    OS + CentOS 7 / VirtualBox 6.0 / VMware-Workstation-Full-15.1.0
    浅谈MySQL Replication(复制)基本原理
    MySQL存储引擎比较
    explain SQL语句性能检测
    看看JavaScript中void(0)的含义
  • 原文地址:https://www.cnblogs.com/Chenshuai7/p/5196875.html
Copyright © 2011-2022 走看看