zoukankan      html  css  js  c++  java
  • PHP-MySQL练习:简单投票

    主页面代码:

    <!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>
    <style>
    .liu
    {
        float:left;
    }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <div id="timu" style="display:block">
    <form action="tpcl.php" method="post">
    
    
    <?php
    include("database.class.php");
    $tm=new database();
    $tm_result=$tm->query("select title from tm");
    echo $tm_result[0][0]."<br>";
    $tmxx_result=$tm->Query("select * from tmxx");
    foreach($tmxx_result as $v)
    {
        echo "<input type='checkbox' value='{$v[0]}' name='xx[]'/>{$v[1]}<br>";
    }
    ?>
    
    <input type="submit" value="投票" />&nbsp;<input  type="button" value="查看结果" onclick="show()"/>
    
    
    
    </form>
    </div>
    
    <div id="jieguo" style="display:none">
    <?php
    $answer=$tm->Query("select options,numbers from tmxx");
    $sum=$tm->Query("select sum(numbers) from tmxx where tmcode=1");
    foreach($answer as $a)
    {
        $bfb=round(($a[1]/$sum[0][0])*100,2);
        echo "<div><span class='liu'>{$a[0]}&nbsp;</span>
                   <div class='liu' style='100px;height:10px;background-color:#CDCDCD'>
                   <div class='liu' style='{$bfb}%;height:10px;background-color:red'></div></div>&nbsp;
                   <span>{$a[1]}</span>&nbsp;
                   <span>({$bfb}%)</span>
             </div>";
    }
    
    
    
    
    
    ?>
    <div><input type="button" value="返回" onclick="show1()" /></div>
    </div>
    </body>
    </html>
    <script>
    function show ()
    {
        document.getElementById("timu").style.display="none";
        document.getElementById("jieguo").style.display="block";
    }
    function show1()
    {
        document.getElementById("timu").style.display="block";
        document.getElementById("jieguo").style.display="none";
    }
    
    </script>

    后台处理代码:

    <?php
    
    $xx=$_POST["xx"];
    include("database.class.php");
    $tpcl=new database();
    if(!empty($xx))
    {
        foreach($xx as $v)
        {
            $tpcl_result=$tpcl->Query("select numbers from tmxx where code='{$v[0]}'");
            $tpcl_result=$tpcl_result[0][0]+1;
            $tpcl_result1=$tpcl->Query("update tmxx set numbers=$tpcl_result where code='{$v[0]}'",1);
        }
        header("location:tp.php");
    }
    else
    {
        header("location:error.php");
    }
  • 相关阅读:
    Jmeter跨线程组传参
    HTTP2 Sampler for JMeter
    全功能Python测试框架:pytest
    pytest + allure + jenkins 生成漂亮的测试报告
    C/C++ 多线程注意事项
    ASIO
    cocos2D-X 线程注意事项
    C/C++ C++ 11 兰姆达
    Android Studio 打包生成正式apk(XXX-release.apk)的两种方式
    C/C++ C++ 11 std::move()
  • 原文地址:https://www.cnblogs.com/Itwonderful/p/5470521.html
Copyright © 2011-2022 走看看