zoukankan      html  css  js  c++  java
  • 练习:投票

    主页面

     1 <?php
     2 include("./dbda.class.php");
     3 $db = new dbda();
     4 $sql = "select * from diaoyantimu limit 0,1";
     5 $attr = $db->Query($sql);
     6 echo "<div>{$attr[0][1]}</div>";
     7 
     8 ?>
     9     <div id="tp">
    10     <form action="TiJiao.php" method="post">
    11     <div>
    12     <?php
    13     $sql1 = "select * from diaoyanxuanxiang";     
    14     $att = $db->Query($sql1);
    15     foreach($att as $v)
    16     {
    17         echo"<input type='checkbox' value='{$v[0]}' name='xx[]'/>{$v[1]}<br />";
    18     }
    19     
    20     ?>
    21     </div>
    22     <div><input type="submit" value="提交" />&nbsp;&nbsp;<input type="button" value="查看结果" onclick="show()" /></div>
    23     </form>
    24     </div>
    25     
    26     <div style="display:none;" id="jieguo">  
    27     <?php
    28     $sql2 = "select sum(Numbers) from diaoyanxuanxiang where TiMuDaiHao='{$attr[0][0]}'";     
    29     $sumnumbers = $db->Query($sql2);
    30     foreach($att as $v1)
    31     {
    32         $bfb = ($v1[2]/$sumnumbers[0][0])*100;
    33         $bfb = round($bfb,2);
    34         echo "<div class='ff'>$v1[1]&nbsp;&nbsp;</div>
    35               <div class='ff'>{$v1[2]}&nbsp;({$bfb}%)</div>
    36               <div class='ff' style=' 100px; height:10px; border:1px solid red'><div style='height:10px; {$bfb}%; background-color:red'></div></div> <br />";
    37     }
    38     ?>
    39     <input type="button" value="返回"  onclick="showfh()" />
    40     </div>
    41     

    JS页面:控制页面隐藏与显示

     1 <script type="text/javascript">
     2 function show()
     3 {
     4     document.getElementById("tp").style.display="none";
     5     document.getElementById("jieguo").style.display="block";
     6 }
     7 function showfh()
     8 {
     9     document.getElementById("tp").style.display="block";
    10     document.getElementById("jieguo").style.display="none";
    11 }
    12 
    13 </script>

    封装数据库类

     1 <?php
     2 class dbda
     3 {
     4     public $host = "localhost";  //数据库地址
     5     public $uid = "root";  //数据库用户名
     6     public $pwd = "";  //数据库密码
     7     //执行sql语句
     8     //参数:sql代表要执行的sql语句  type是sql语句的类型0代表查询1代表其他   db代表要操作的数据库
     9     public function Query($sql,$type=0,$db="mydb") 
    10     {
    11         //1.造连接对象
    12         $dbconnect = new MySQLi($this->host,$this->uid,$this->pwd,$db);
    13         !mysqli_connect_error() or die("连接失败!");
    14         $result = $dbconnect->query($sql);
    15         if($type ==0)
    16         {
    17             return $result->fetch_all();
    18         }
    19         else
    20         {
    21             return $result;
    22         }
    23     }
    24 }
  • 相关阅读:
    1105 Spiral Matrix (25分)(蛇形填数)
    1104 Sum of Number Segments (20分)(long double)
    1026 Table Tennis (30分)(模拟)
    1091 Acute Stroke (30分)(bfs,连通块个数统计)
    1095 Cars on Campus (30分)(排序)
    1098 Insertion or Heap Sort (25分)(堆排序和插入排序)
    堆以及堆排序详解
    1089 Insert or Merge (25分)
    1088 Rational Arithmetic (20分)(模拟)
    1086 Tree Traversals Again (25分)(树的重构与遍历)
  • 原文地址:https://www.cnblogs.com/zk0533/p/5475624.html
Copyright © 2011-2022 走看看