当前位置:首页 > 综合实例 > 列表

PHP+MySQL实现的简单投票系统实例

发布:smiling 来源: PHP粉丝网  添加日期:2021-07-11 13:05:00 浏览: 评论:0 

这篇文章主要介绍了PHP+MySQL实现的简单投票系统,以完整实例形式分析了PHP+MySQL实现投票功能的具体功能代码与相关技巧,需要的朋友可以参考下。

本文实例讲述了PHP+MySQL实现的简单投票系统,分享给大家供大家参考,具体如下:

  1. <html> 
  2. <head><title>手机系统调查问卷</title> 
  3. <style type="text/css"> 
  4. <!-- 
  5. span{ 
  6.   width:600px; 
  7.   height:100px; 
  8.   background-color:write; 
  9.   postion:relative; 
  10.   border:1px #cccccc solid; 
  11. } 
  12. div{ 
  13.   width:60px; 
  14.   height:1px; 
  15.   background-color:blue; 
  16.   postion:absolute; 
  17.   bottom:0; 
  18. } 
  19. --> 
  20. </style> 
  21. </head> 
  22. <body> 
  23. 你现在使用的手机是什么系统? 
  24. <form id="form1" method="POST" action="count.php"> 
  25. <input type="radio" name="phone" value="1"> Android安卓 
  26. <input type="radio" name="phone" value="2"> Symbian塞班 
  27. <br> 
  28. <input type="radio" name="phone" value="3"> iphone苹果 
  29. <input type="radio" name="phone" value="4"> Google谷歌 
  30. <br> 
  31. <input type="radio" name="phone" value="5"> Winphone微软 
  32. <input type="radio" name="phone" value="6"> 其它 
  33. <br> 
  34. <input type="submit" value="提交"> 
  35. </form> 
  36. <span> 
  37. 当前票数:<br> 
  38. <?php 
  39. include 'connect.php'; 
  40. $sql="select answer from countone"; 
  41. $rs=mysql_query($sql); 
  42. $total=mysql_num_rows($rs); 
  43. $sql="select * from countone where answer=1"; 
  44. $rs=mysql_query($sql); 
  45. $android=mysql_num_rows($rs); 
  46. $sql="select * from countone where answer=2"; 
  47. $rs=mysql_query($sql); 
  48. $symbian=mysql_num_rows($rs); 
  49. $sql="select * from countone where answer=3"; 
  50. $rs=mysql_query($sql); 
  51. $iphone=mysql_num_rows($rs); 
  52. $sql="select * from countone where answer=4"; 
  53. $rs=mysql_query($sql); 
  54. $google=mysql_num_rows($rs); 
  55. $sql="select * from countone where answer=5"; 
  56. $rs=mysql_query($sql); 
  57. $winphone=mysql_num_rows($rs); 
  58. $sql="select * from countone where answer=6"; 
  59. $rs=mysql_query($sql); 
  60. $other=mysql_num_rows($rs); 
  61. ?> 
  62. <table border="0"> 
  63. <th>android</th><th>Symbian</th><th>iphone</th><th>Google</th><th>winphone</th><th>other</th> 
  64. <tr> 
  65. <td><?php echo $android ?>票</td> 
  66. <td><?php echo $symbian ?>票</td> 
  67. <td><?php echo $iphone ?>票</td> 
  68. <td><?php echo $google ?>票</td> 
  69. <td><?php echo $winphone ?>票</td> 
  70. <td><?php echo $other ?>票</td> 
  71. </tr> 
  72. <tr> 
  73. <td><?php for ($i=1;$i<=$android/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td> 
  74. <td><?php for ($i=1;$i<=$symbian/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td> 
  75. <td><?php for ($i=1;$i<=$iphone/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td> 
  76. <td><?php for ($i=1;$i<=$google/$total+1;$i=$i+0.1){  echo "<div></div>"; } ?></td> 
  77. <td><?php for ($i=1;$i<=$winphone/$total+1;$i=$i+0.1){ echo "<div></div>"; } ?></td> 
  78. <td><?php for ($i=1;$i<=$other/$total+1;$i=$i+0.1){ echo "<div></div>"; } ?></td> 
  79. </tr> 
  80. </table> 
  81. </span> 
  82. </body> 
  83. </html> 

写的有点啰嗦,有点笨但很实用

  1. <?php 
  2. include 'connect.php'; 
  3. $name=$_POST['phone']; 
  4. $sql="insert into countone values(null,$name,now(),null)"; 
  5. mysql_query($sql); 
  6. ?> 
  7. <script type="text/javascript"> 
  8.  alert ("投票成功!"); 
  9.  location="question.php"; 
  10. </script> 

链接mysql:

  1. <?php 
  2. mysql_connect("localhost","root",""); 
  3. mysql_select_db("vote"); 
  4. mysql_query("set names utf8"); 
  5. ?>

Tags: PHP+MySQL投票系统

分享到: