使用php+mysql+xml完成一个调查问卷
本人根据php典型模块与项目实战大全此书所完成的一个调查问卷,同时管理员可以进行修改调查内容
同时用到了一个css文件,借鉴于
http://www.wufangbo.com/div-css-vote/
需要5个php文件:admin.php、update.php、view.php、result.php、vote.php、
首先在WWW下新建一个文件夹 此处为名为"diaocha" 本人的端口号为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;
}
?>
<html>
<head>
<table width="98%" border=0 align="center" cellpadding="3" cellpadding="1">
<tr>
<td height="28" ><b>调查管理</b></td>
</tr>
<tr height="200" valign="top">
<form name="form1" method="post" action="update.php">
<input type="hidden" name = "aid" value="<?php echo $aid?>">
<table width="100%" border="0"cellpadding="4" cellspacing="4">
<tr>
<td width="15%" align="center">调查项目:</td>
<td width="85%">
<input name="votename" type="text" id="votename" value="<?php echo $row['Votename'];?>">
</td>
</tr>
<tr>
<td align="center">调查总人数:</td>
<td>
<input name="totalcount" type="text" id="totalcount" value="<?php echo $row['Totalcount'];?>">
</td>
</tr>
<tr>
<td align="center">开始时间:</td>
<td>
<input name="starttime" type="text" id="starttime" value="<?php echo $row['Starttime'];?>">
</td>
</tr>
<tr>
<td align="center">结束时间:</td>
<td>
<input name="endtime" type="text" id="endtime" value="<?php echo $row['Endtime'];?>">
</td>
</tr>
<tr>
<td align="center">投票项:</td>
<td>
<textarea name="votenote" rows="8" id ="votenote" style="width:80%">
<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></textarea></td>
</tr>
<tr>
<td height="47"> </td>
<td><input type="submit" name="Submit" value="保存调查数据">
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
</tr>
</head>
</html>
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、view.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完成一个调查问卷的更多相关文章
- <问吧>调查问卷心得体会
<问吧>调查问卷心得与体会 在这之前,我们已经组成了一个六个人的小团队---“走廊奔跑队”,我们这次做的这个项目的名称是:问吧.在项目实施之前,我们必做的一步就是需求分析,目的就是充分了解 ...
- SAP CRM调查问卷的评分和图表显示功能介绍
SAP CRM里我们使用事务码CRM_SURVEY_SUITE创建一个调查问卷(Survey): 其中调查问卷的问题和答案均可分配权值(Rate),最后该问卷总的分数等于每个问题的权值乘以客户选择答案 ...
- android 实现调查问卷-单选-多选
非常久没写东西了.今天来总结下有关android调查问卷的需求实现. 转载请加地址:http://blog.csdn.net/jing110fei/article/details/46618229 先 ...
- 使用ABAP代码提交SAP CRM Survey调查问卷
Jerry之前曾经写过两篇关于SAP CRM Survey调查问卷的技术文章: SAP CRM Survey调查问卷的模型设计原理解析 如何使用SAP CRM Marketing Survey创建一个 ...
- springMVC 调查问卷系统 record
Maven下的依赖包有两个 spring-web和springWebMVC springwebMVC包含spring-web依赖, 但是spring-web的等级大于Spring-webmvc 没有 ...
- java web(一) 使用sql标签库+tomcat+mysql手动创建一个jsp练习总结
2016-09-0111:06:53 使用sql标签库+tomcat+mysql手动创建一个jsp 1. 1.1安装tomcat ...
- "琳琅满屋"调查问卷 心得体会及结果分析
·关于心得体会 当时小组提出这个校园二手交易市场的时候,就确定了对象范围,仅仅是面向在校大学生,而且在我们之前就已经有了很多成功的商品交易的例子可以让我们去借鉴,再加上我们或多或少的有过网 ...
- 关于“Durian”调查问卷的心得体会
这周我们做了项目着手前的客户需求调查,主要以调查问卷的方式进行.其实做问卷调查并不是想象中的那么简单,首先要确定问卷调查的内容,每一个问题都要经过深思熟虑,字字斟酌,既要切合问卷主要目的,又要简洁扼要 ...
- 从Adobe调查问卷看原型设计工具大战
近年国内外原型设计工具新品频出,除了拥趸众多的老牌Axure在RP 8之后没有什么大的动作,大家都拼了命地在出新品.今天 inVision 的 Craft 出了 2.0 的预告视频,明天 Adobe ...
随机推荐
- Linux磁盘修复命令----fsck
使用fsck命令修复磁盘时 一定要进入单用户模式去修复 语 法fsck.ext4[必要参数][选择参数][设备代号] 功 能fsck.ext4 命令: 针对ext4型文件系统进行检测 参数 -a 非 ...
- WebLogic上的项目无法更新,删除项目缓存
/root/bea/user_projects/domains/base_domain/servers/AdminServer/tmp/ /root/bea/user_projects/domains ...
- 尤雨溪的vue怎么学,应该从vue-cli开始,为什么?
带手机验证码登陆, 带全套购物车系统 带数据库 前后端分离开发 带定位用户功能 数据库代码为本地制作好了 带支付宝支付系统 带django开发服务器接口教程 地址: https://www.dua ...
- 广深小龙-基于unittest、pytest自动化测试框架之demo来学习啦!!!
基于unittest.pytest自动化测试框架之demo,赶紧用起来,一起学习吧! demo分为两个框架:①pytest ②unittest demo 中 包含 web.api 自动化测试框架 ...
- 多方法解决设置width:100%再设置margin或padding溢出的问题
2019独角兽企业重金招聘Python工程师标准>>> 当设置了父元素的宽度,子元素设置宽度为100%后再在加上子元素上添加padding或margin值就会溢出.举个例子: < ...
- Qt之QListWidget:项目的多选与单选设置
2019独角兽企业重金招聘Python工程师标准>>> #include "widget.h" #include <QApplication> #in ...
- 数学--数论--Hdu 1452 Happy 2004(积性函数性质+和函数公式+快速模幂+乘法逆元)
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your ...
- Java笔记(day13)
多线程: 进程:正在进行中的程序(直译) 线程:执行路径,就是进程中负责程序执行的控制单元(执行路径): 一个进程中可以多个路径,称为多线程 一个进程至少一个线程 每一个线程都有自己运行的内容,这个内 ...
- spring学习笔记(二)spring中的事件及多线程
我们知道,在实际开发中为了解耦,或者提高用户体验,都会采用到异步的方式.这里举个简单的例子,在用户注册的sh时候,一般我们都会要求手机验证码验证,邮箱验证,而这都依赖于第三方.这种情况下,我们一般会通 ...
- Day_14【IO流】扩展案例3_对文本文件中的字符串内容进行反转
分析以下需求,并用代码实现 项目根路径下有text.txt文件,内容如下 我爱黑马 123456 利用IO流的知识读取text.txt文件的内容反转后写入text.txt文件中 654321 马黑爱我 ...