> 백엔드 개발 > PHP 튜토리얼 > PHP와 MySql을 이용하여 위챗 투표 기능을 구현한 예

PHP와 MySql을 이용하여 위챗 투표 기능을 구현한 예

黄舟
풀어 주다: 2023-03-16 13:30:01
원래의
1459명이 탐색했습니다.

1. 기본 투표 페이지:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

<!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>

</head>

   

<body>

   

<form action="TouChuLi.php" method="post">

<?phpinclude ("DBDA.class.php");$db=new DBDA();//从调研题目表中找出题目代号和名称

$sql="select * from diaoyantimu limit 0,1";

$arr=$db->query($sql);

$tmmc=$arr[0][1];$tmdh=$arr[0][0];echo "<p><h2>{$tmmc}:</h2></p>";

//从调研选项表中输出选项内容:

$sqlxx="select * from diaoyanxuanxiang where timudaihao=&#39;{$tmdh}&#39;";

$arrxx=$db->query($sqlxx);

echo "<p id=&#39;list&#39;>";

foreach ($arrxx as $v)

echo "<p><input type=&#39;checkbox&#39; value=&#39;{$v[0]}&#39; name=&#39;xx[]&#39;>{$v[1]}</p><br />";

?>

<input type="submit" value="提交">

<input type="button" value="查看结果" id="check" onclick="Showjieguo()">

</form>

</p>

   

<p id="jieguo" style="display:none">

<?php//计算总人数:$sqlzs="select sum(numbers) from diaoyanxuanxiang where timudaihao=&#39;{$tmdh}&#39;";$zrs=$db->query($sqlzs); 

foreach ($arrxx as $v)

{   

  $name=$v[1];  $number=$v[2];  if($zrs[0][0]==0)

   {     $bfb = 0;

   }   else

   {     $bfb = ($number/$zrs[0][0])*100;

   $bfb=round($bfb,2);  echo "<p>

    <span class=&#39;x&#39;>{$name} </span>

    <p class=&#39;x&#39; style=&#39;width:200px; height:10px; background-color:#808080&#39;>

    <p style=&#39;width:{$bfb}%; height:10px; background-color:#FF8040&#39;> </p>

    </p>

    <span class=&#39;x&#39;>{$number} </span>

    <span class=&#39;x&#39;>{$bfb}% </span>

    </p>

    <br />    ";

}?>

<input type="button" value="返回" id="fanhui" onclick="Showfanhui()">

</p>

<script>function Showjieguo()

{

  document.getElementById("list").style.display="none";

  document.getElementById("jieguo").style.display="block";

  }function Showfanhui()

{

  document.getElementById("list").style.display="block";

  document.getElementById("jieguo").style.display="none";

  }</script>

   

</body>

</html>

로그인 후 복사

2. 처리 중인 투표 페이지:


1

2

3

4

5

6

7

8

<?php$arr=$_POST["xx"];include ("../DBDA.class.php");$db=new DBDA(); 

   

foreach($arr as $v)

$sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids = &#39;{$v}&#39;"

$db->Query($sql,1);//1代表$sql的类型

}

header ("location:TouPiao.php");

?>

로그인 후 복사

3 데이터베이스에 액세스하고 참조용으로 캡슐화합니다.

위 내용은 PHP와 MySql을 이용하여 위챗 투표 기능을 구현한 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿