zoukankan      html  css  js  c++  java
  • 内测投票

    create table DiaoYanTiMu

    (  Ids int(10) auto_increment not null primary key(),//把所需要的都写上中间不需要符号隔开,设自增长列类型必须是int,主键的话必须不能为空not null,

       Title varchar(50) not null

    );//这里的;一定不要忘记,要不然报错还找不出来,

    insert into DiaoYanTiMu values(null,"35岁的发展方向");//因为设了自增长列,所以第一个列名Ids写为null,

    create table DiaoYanXuanXiang
    ( Ids int(10) not null auto_increment primary key,
    Options varchar(50) not null,
    Numbers int(10) not null,
    TiMuDiaoYan int(10) not null
    );
    insert into DiaoYanXuanXiang values(null,"aaa",0,001);
    insert into DiaoYanXuanXiang values(null,"bbb",0,001);
    insert into DiaoYanXuanXiang values(null,"ccc",0,001);
    insert into DiaoYanXuanXiang values(null,"ddd",0,001);
    insert into DiaoYanXuanXiang values(null,"eee",0,001);

    接下来自己做的过程中卡壳了,不知道怎么要选项前面的复选框出现,没有想到可以遍历,而且html写在php中总是各种报错,以为是不能写多以就不知道怎么做了,后来反应过来是""的问题,因为在php中输出echo"";已经有了"",所以里面的内容要用'',所以被坑的不轻是真的没有反应过来问题在引号上……粗心真的使不得,半个'有时候找半天发现是自己手误少了,可是出来的结果直接变形

    <!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">
    #xxlist{ 250px; height:200px}
    #jieguo{250px; height:200px}
    .a{float:left;}
    </style>
    </head><body>
    <form action="jieguo.php" method="post">
    <?php
    include("./ChaXun.class.php");//加载封装好的类,之前自己封装了一个,把那个copy到当前文件夹下面了
    $tp=new ChaXun();
    $sql="select * from DiaoYanTiMu limit 0,1";//limit之前没怎么用过,0,1,表示越过0行,从第一行开始
    $attr=$tp->Query($sql);//就一行数据
    //var_dump($attr);

    $tmmc=$attr[0][1]; $tmdh=$attr[0][0]; echo"<div>题目名称:{$tmmc}</div>"; $sqlxx = "select * from DiaoYanXuanXiang where TiMuDiaoYan='{$tmdh}'";//选项表中的TiMuDiaoYan就是主键Ids $attrxx=$tp->Query($sqlxx); //var_dump($attrxx); echo"<div id='xxlist'>"; foreach($attrxx as $v)//遍历$attrxx { 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 TiMuDiaoYan='{$tmdh}'";
        $attrsum=$tp->Query($sqlsum);
        foreach($attrxx as $v)
        { $xxm=$v[1];
        //var_dump($xxm);
           $no=$v[2];
           $bfb=($no/$attrsum[0][0])*100;
           $bfb=round($bfb,2);
            echo"<div style='250px;height:30px'>
            <span class='a'>{$xxm}</span>
            
            <div class='a' style='100px; height:10px; border:solid 1px red'>
               <div style='{$bfb}%; height:10px; background-color:red'></div>
            </div>
            
            <span class='a'>{$no}&nbsp;</span>
            <span class='a'>{$bfb}%</sapn>    
                
            </div>";
            
        }
        
        ?>
        <input type="button" value="返回" id="fanhui" onclick="ShowList()" />
    </div>
    </body>
    <script type="text/javascript">
    function ShowJieGuo()
    {
        document.getElementById("xxlist").style.display="none";
        document.getElementById("jieguo").style.display="block";
    }
    function ShowList()
    {
        document.getElementById("xxlist").style.display="block";
        document.getElementById("jieguo").style.display="none";
    
    }
    </script>
    
    </html>

    提交之后,转换到另一个jieguo.php页面,处理提交需要处理的内容

    <?php
    $attr=$_POST["xx"];
    var_dump($attr);
    include("./ChaXun.class.php");
    $db=new ChaXun();
    foreach($attr as $v)
    {
        $sql="update DiaoYanXuanXiang set Numbers=Numbers+1 where Ids='{$v}'";
        $db->Query($sql,1);//这里需要注意,type默认为0发表查询,这里update是更改不是查询所以type的值需要改变
    }
    header("location:toupiao.php");//处理结束跳转回toupiao.php页面

  • 相关阅读:
    VMware ESXI 5.5 注册码
    NetScaler Active-Active模式
    Citrix NetScaler HA(高可用性)解析
    服务管理--systemctl命令
    CentOS7 安装 webgoat 7.1 简介
    Codefoces 723B Text Document Analysis
    Codefoces 723A The New Year: Meeting Friends
    ECJTUACM16 Winter vacation training #1 题解&源码
    信息学奥赛一本通算法(C++版)基础算法:高精度计算
    从零开始学算法:高精度计算
  • 原文地址:https://www.cnblogs.com/nannan-0305/p/5470578.html
Copyright © 2011-2022 走看看