이 글의 내용은 php+mysql+xml 구현에 관한 설문지(코드)에 관한 내용으로, 참고할만한 가치가 있으니 참고하시면 도움이 되실 것 같습니다.
PHP 일반 모듈 및 프로젝트 실습 책을 기반으로 설문지를 작성하는 동시에 관리자는 설문 내용을 수정할 수 있습니다.
동시에
http에서 가져온 CSS 파일을 사용했습니다. ://www.wufangbo.com /p-css-vote/
5개의 PHP 파일이 필요합니다: admin.php, update.php, view.php, result.php, vote.php,
먼저 아래에 새 폴더를 만듭니다. 여기 이름이 "diaocha"인 WWW 내 포트 번호는 8080
데이터베이스는 다음과 같습니다. 라이브러리 이름은 cms_vote 테이블 이름은 vote
Votenote 내부 내용은
<movies>
<movie>
<title>您想去哪个城市:</title>
<id>1</id>
<count>350</count>
<content>广东</content>
</movie>
<movie>
<title>您想去哪个城市:</title>
<id>2</id>
<count>47</count>
<content>湖南</content>
</movie>
<movie>
<title>您想去哪个城市:</title>
<id>3</id>
<count>118</count>
<content>上海</content>
</movie>
<movie>
<title>您想去哪个城市:</title>
<id>4</id>
<count>122</count>
<content>北京</content>
</movie>
<movie>
<title>您想去哪个城市:</title>
<id>5</id>
<count>80</count>
<content>湖北</content>
</movie>
</movies>
로그인 후 복사
1.admin .php
<?php
$con = mysql_connect('localhost','root','root')or die("could not connect database");//此处根据自己的数据库的名字,密码进行修改
mysql_query("set names utf8");
mysql_select_db('cms_vote')or die("could not select database");
$aid = $_GET['aid'];
if(!empty($aid)){
$sql='SELECT *FROM vote ';
//WHERE aid=".$aid."';
$result = mysql_query($sql,$con);
$row = mysql_fetch_array($result);
}
else{
echo '<script>alert(\'调查异常\');</script>';
exit;
}
?>
로그인 후 복사
调查管理 |
로그인 후 복사
2, update.php
<?php
$con = mysql_connect('localhost','root','root')or die("could not connect database");//此处根据自己的数据库的名字,密码进行修改
mysql_query("set names utf8");
mysql_select_db('cms_vote')or die("could not select database");
$aid = $_POST['aid'];
$votename=$_POST['votename'];
$starttime=$_POST['starttime'];
$endtime=$_POST['endtime'];
$votenote=$_POST['votenote'];
$totalcount=$_POST['totalcount'];
if(!empty($aid))
{
$sql = "UPDATE vote SET Votename= '".$votename."',
Starttime='".$starttime."', Endtime='".$endtime."',
Totalcount='".$totalcount."', Votenote='".$votenote."' WHERE
aid='".$aid."'order by aid desc limit 1;";
$result = mysql_query($sql);
if(!empty($result)){
echo '<script>alert(\'数据保存成功\');</script>';
echo "您的调查问卷已生效!";
}
else
{
echo '<script>alert(\'数据保存失败\');</script>';
exit();
}
}
else{
echo '<script>alert(\'调查异常\');</script>';
exit();
}
?>
로그인 후 복사
확인에 성공했습니다: http://localhost:8080/diaocha/admin.php?aid=1
(참고 ?aod=1) 형식을 추가해야 합니다. 영어 형식으로
설문조사 데이터 저장 버튼을 누르면 나타납니다
설문지가 적용된 것으로 나타납니다
3, 보기. php
<?php
$voteitem = $_POST['voteitem'];
$con = mysql_connect('localhost','root','root')or die("could not connect database");//密码用户名按照自己的修改
mysql_query("set names utf8");
mysql_select_db('cms_vote')or die("could not select database");
$sql="SELECT *FROM vote";
$result = mysql_query($sql,$con);
$arr = mysql_fetch_array($result);
$xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$xmlstr.=$arr['Votenote'];
$xml = simplexml_load_string($xmlstr);
$b[]=Array();
$a[]=Array();
for($i=0;$i<5;$i++){
$b[$i]=$xml->movie[$i]->count;
$a[$i]=$xml->movie[$i]->count+1;
}
for($i=0;$i<5;$i++){
$b[$i]=$a[$i];
$xmlstra[$i]="<movies>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>1</id>
<count>".$b[0]."</count>
<content>". $xml->movie[0]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>2</id>
<count>".$b[1]."</count>
<content>". $xml->movie[1]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>3</id>
<count>".$b[2]."</count>
<content>". $xml->movie[2]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>4</id>
<count>".$b[3]."</count>
<content>". $xml->movie[3]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>4</id>
<count>".$b[4]."</count>
<content>". $xml->movie[4]->content ."</content>
</movie>
</movies>";
}
if($voteitem!=null){
$sql = "UPDATE vote SET Totalcount=Totalcount+1,Votenote='".$xmlstra[$voteitem]."' order by aid desc limit 1";
$result = mysql_query($sql);
$url = 'result.php?aid=1';
switch($voteitem){
case 0:
{
if(!empty($result)){
echo '<script>alert("投票1成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 1:
{
if(!empty($result)){
echo '<script>alert("投票2成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 2:
{
if(!empty($result)){
echo '<script>alert("投票3成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 3:
{
if(!empty($result)){
echo '<script>alert("投票4成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 4:
{
if(!empty($result)){
echo '<script>alert("投票5成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
}
}
else{
echo '<script>window.close();</script>';
}
?>
로그인 후 복사
다음 결과가 나타납니다
4.vote.php
<?php
$voteitem = $_POST['voteitem'];
$con = mysql_connect('localhost','root','root')or die("could not connect database");
mysql_query("set names utf8");
mysql_select_db('cms_vote')or die("could not select database");
$sql="SELECT *FROM vote";
$result = mysql_query($sql,$con);
$arr = mysql_fetch_array($result);
$xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$xmlstr.=$arr['Votenote'];
$xml = simplexml_load_string($xmlstr);
$b[]=Array();
$a[]=Array();
for($i=0;$i<5;$i++){
$b[$i]=$xml->movie[$i]->count;
$a[$i]=$xml->movie[$i]->count+1;
}
for($i=0;$i<5;$i++){
$b[$i]=$a[$i];
$xmlstra[$i]="<movies>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>1</id>
<count>".$b[0]."</count>
<content>". $xml->movie[0]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>2</id>
<count>".$b[1]."</count>
<content>". $xml->movie[1]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>3</id>
<count>".$b[2]."</count>
<content>". $xml->movie[2]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>4</id>
<count>".$b[3]."</count>
<content>". $xml->movie[3]->content ."</content>
</movie>
<movie>
<title>". $xml->movie[0]->title ."</title>
<id>4</id>
<count>".$b[4]."</count>
<content>". $xml->movie[4]->content ."</content>
</movie>
</movies>";
}
if($voteitem!=null){
$sql = "UPDATE vote SET Totalcount=Totalcount+1,Votenote='".$xmlstra[$voteitem]."' order by aid desc limit 1";
$result = mysql_query($sql);
$url = 'result.php?aid=1';
switch($voteitem){
case 0:
{
if(!empty($result)){
echo '<script>alert("投票1成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 1:
{
if(!empty($result)){
echo '<script>alert("投票2成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 2:
{
if(!empty($result)){
echo '<script>alert("投票3成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 3:
{
if(!empty($result)){
echo '<script>alert("投票4成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
case 4:
{
if(!empty($result)){
echo '<script>alert("投票5成功!");location.href="'.$url.'"</script>';
exit();
}
break;
}
}
}
else{
echo '<script>window.close();</script>';
}
?>
로그인 후 복사
5.result.php
<?php
$con = mysql_connect('localhost','root','root')or die("could not connect database");
mysql_query("set names utf8");
mysql_select_db('cms_vote')or die("could not select database");
$aid = $_GET['aid'];
if(!empty($aid)){
$sql="SELECT *FROM vote WHERE aid='".$aid."'";
$result = mysql_query($sql,$con);
$arr = mysql_fetch_array($result);
$xmlstr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
$xmlstr.=$arr['Votenote'];
$xml = simplexml_load_string($xmlstr);
$n0=$xml->movie[0]->count/$arr['Totalcount'];
$n1=$xml->movie[1]->count/$arr['Totalcount'];
$n2=$xml->movie[2]->count/$arr['Totalcount'];
$n3=$xml->movie[3]->count/$arr['Totalcount'];
$n4=$xml->movie[4]->count/$arr['Totalcount'];
}
/*else
{
echo '<script>alert(\'调查异常\');</script>';
exit;
}*/
?>
로그인 후 복사
<html>
<head>
<style >
#graphbox{
border:1px solid #e7e7e7;
padding:10px;
width:545px;
background-color:#f8f8f8;
margin:5px 0;//这是最大的一个div
}
.itemname{
width:70px;
font-weight:700;
font-size:14px;
line-height:18px;
height:18px;
padding:2px;
text-align:right;
margin-right:atuo;
}
.percent{
width:150px;
float:right;
font-size:13px;
line-height:18px;
height:18px;
padding:2px;
color:#555;
text-align:left;
margin-right:3px;
}
.graph{
position:relative;
background-color:#F0EFEF;
border:1px solid #cccccc;
font-size:13px;
width:300px;
font-weight:700;
float:right;
margin-right:3px;
}
.color1, .color2, .color3, .color4, .color5{
position:relative;
text-align:left;
color:#ffffff;
height:18px;
display:block;
}
.graph .color1{background-color:#afb4db;}
.graph .color2{background-color:#84bf96;}
.graph .color3{background-color:#ea66a6;}
.graph .color4{background-color:#50b7c1;}
.graph .color5{background-color:#ffd400;}
.font1{color:#669999;}
.font2{color:#6699FF;}
.font3{color:#FF9900;}
.font4{color:#FF3333;}
</style>
<body>
<h3><?php echo $arr['Votename']; ?></h3>
<td>调查结果</td>
<div>
<td>调查开始时间:<?php
echo $arr['Starttime']; ?> 调查结束时间:<?php echo $arr['Endtime'];
?> 调查总人数:<?php echo $arr['Totalcount'];
?></td></td>
<div>
<div id="graphbox">
<div class="little_box">
<div
class="percent"><?php echo sprintf("%01.0f",$n0*100).'%';?>
<?php echo $xml->movie[0]->count;?></div>
<div class="graph">
<span class="color1" style="width:<?php echo sprintf("%01.0f",$n0*100).'%';?>"> </span></div>
<div class="itemname font1"><?php echo $xml->movie[0]->content;?></div>
</div>
<div class="little_box">
<div
class="percent"><?php echo sprintf("%01.0f",$n1*100).'%';?>
<?php echo $xml->movie[1]->count;?></div>
<div class="graph">
<span class="color2" style="width:<?php echo sprintf("%01.0f",$n1*100).'%';?>"> </span></div>
<div class="itemname font2"><?php echo $xml->movie[1]->content;?></div>
</div>
<div class="little_box">
<div
class="percent"><?php echo sprintf("%01.0f",$n2*100).'%';?>
<?php echo $xml->movie[2]->count;?> </div>
<div class="graph">
<span class="color3" style="width:<?php echo sprintf("%01.0f",$n2*100).'%';?>;"> </span></div>
<div class="itemname font3"><?php echo $xml->movie[2]->content;?></div>
</div>
<div class="little_box">
<div
class="percent"><?php echo sprintf("%01.0f",$n3*100).'%';?>
<?php echo $xml->movie[3]->count;?> </div>
<div class="graph">
<span class="color4" style="width:<?php echo sprintf("%01.0f",$n3*100).'%';?>;"> </span></div>
<div class="itemname font4"><?php echo $xml->movie[3]->content;?></div>
</div>
<div class="little_box">
<div
class="percent"><?php echo sprintf("%01.0f",$n4*100).'%';?>
<?php echo $xml->movie[4]->count;?> </div>
<div class="graph">
<span class="color5" style="width:<?php echo sprintf("%01.0f",$n4*100).'%';?>;"> </span></div>
<div class="itemname font5"><?php echo $xml->movie[4]->content;?></div>
</div>
</div>
</body>
</head>
</html>
로그인 후 복사
위 내용은 php+mysql+xml(코드)로 구현된 설문지의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
-
2019-04-16 16:04:28
-
2020-09-15 11:26:00
-
2020-09-10 14:26:14
-
2020-09-08 11:06:15
-
2020-09-09 09:46:36
-
2020-10-12 14:51:04
-
2020-09-10 14:40:02
-
2019-04-24 16:20:55
-
2020-10-13 11:40:03
-
2019-04-15 14:06:21