• 例题:投票,图形显示


    题目要求:

    主页面,(修改页面)

    <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.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>";
    }
    //因为是复选框,不确定选几个,所以用数组 xx[] 定义name
    ?> <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="ShowList()" /> </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> </html>

    点击“查看结果”,显示图 2

    点击“返回”,显示图 1

    看不到的,chuli.php 处理页面,(updatechuli.php页面)

    <?php
    
    $attr = $_POST["xx"];
    include("../DBDA.php");
    $db = new DBDA();
    
    foreach($attr as $v)
    {
        $sql = "update DiaoYanXuanXiang set Numbers = Numbers+1 where Ids = '{$v}'";
        $db->Query($sql,0);
    }
    
    header("location:test.php");

    总结:PHP访问页面,化作:增,删,改,查-----解题

  • 相关阅读:
    asp.net core的DI框架思考以及服务实例的获取方式总结
    并发相关随笔(持续更新)
    为什么Dotnet Core的DI默认是在控制器中注入
    在控制台下玩玩dotnet core内置原生的DI
    asp.net core 依赖注入实现全过程粗略剖析(3)
    EF 下如何更新数据表数据
    asp.net core 依赖注入实现全过程粗略剖析(2)
    asp.net core 依赖注入实现全过程粗略剖析(1)
    【MongoDB 高可用篇】MongoDB Sharding Cluster启动和关闭过程
    【MongoDB 高可用篇】MongoDB Sharding Cluster集群环境搭建
  • 原文地址:https://www.cnblogs.com/wanlibingfeng/p/5471509.html
Copyright © 2020-2023  润新知