这个简单的PHP问卷调查页从网上查阅了很多资料,自己修改了不少,但是到现在bug依然很多,在此发帖求助高手帮忙,不胜感激!比如调查页面的bug是怎么产生的,然后怎么才能排除?调查结果页面那个计算比例的功能为什么只能计算正确第一道?小弟特此把源码发给大家,寻求帮助,不胜感激!新手望多多指教!在此先谢了!<html>
----------------------------------------------调查页面index.php----------------------------------------
<head>
<title>大连民族学院3食堂1楼食堂消费者满意度问卷调查-调查</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
<!--
.hei12 {  font-family: "宋体"; line-height: 22px; color: 262626; text-decoration: none; font-size: 12px}
.hei13 {  font-family: "宋体"; line-height: 22px; color: 262626; text-decoration: none; font-size: 14px}
.hei16 {
font-family: "宋体";
line-height: 26px;
color: 830000;
text-decoration: none;
font-size: 25px;
font-weight: bold
}
a:hover { text-decoration: underline}
td {  font-family: "宋体"; font-size: 12px; text-decoration: none}
.shui {  font-family: "宋体"; font-size: 12px; line-height: 16px; color: #262626; text-decoration: underline}
.bai12c {  font-family: "宋体"; font-size: 14px; line-height: 20px; font-weight: bold; color: #FFFFFF; text-decoration: none}
.bai12 {  font-family: "宋体"; font-size: 14px; line-height: 28px; font-weight: normal; color: #000000; text-decoration: none}
.hong12 {  font-family: "宋体"; font-size: 14px; line-height: 20px; font-weight: normal; color: #BE1200; text-decoration: none}
.lan12 {  font-family: "宋体"; font-size: 12px; line-height: 16px; color: 0004A0; text-decoration: none}
.gd {  font-family: "宋体"; font-size: 12px; line-height: 20px; color: 2F6A03; text-decoration: none}
.bt { font-family: "宋体";  font-size: 14px; color: #2F6A03; text-decoration: none; filter: Glow(Color=#ffffff, Strength=2); line-height: 22px; font-weight: bold; }
.bian01 {   background-color: #FEFDE6; border: 1px #996600 solid}
.bian02 {   background-color: #F4EEEE; border: 1px #AFAAAA solid}
body,td,th {
font-size: 15px;
color: #000;
font-weight: bold;
}
body {
background-color: #999;
}
-->
</style>
</head>
<body bgcolor="#999999" text="#000033" leftmargin="0" topmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<div align="center"> 
  <table width="800" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td width="800" class="bian01" valign="top"> 
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="26">&nbsp;</td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="40"> 
              <div align="center" class="hei16">
                <p align="center">大连民族学院3食堂1楼食堂消费者满意度问卷调查</p>
              </div>
            </td>
          </tr>
        </table>
        <table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="A0A0A0" height="1">
          <tr> 
            <td></td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="26">&nbsp;</td>
          </tr>
        </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td height="40"> 
                  
<form name="form1" method="get" action="?a=add" ;>
  <table width="678" align="center" cellpadding="2" cellspacing="2">
      
<?php
//读取标题 $t = file_get_contents("./data/t.txt");
$t = explode("\n", $t);//读取选项 $a = file_get_contents("./data/a.txt");
$a = explode("\n", $a);

//读取结果 $r = file_get_contents("./data/r.txt");
$r = explode("\n", $r);

//输出显示
    for($i=0; $i<count($t); $i++){
echo "\n<tr><td height=\"22\" class=\"lan12\"><b>".$t[$i]."</b></td></tr>\n";
$a1 = explode("|", $a[$i]);
$r1 = explode("|", $r[$i]);
for($k=0; $k < count($a1); $k++){
          echo  "<tr>
  <td height=\"22\">
  <input type='radio' name='a".$i."' id='a".$i."' value='".$k."' checked/>";
     echo $a1[$k];
     echo "\n</td></tr>\n";
     }
    } //获取GET
$l1 = $_GET['a'];
//投票
if($l1 == 'add'){
print_r($_POST);
print_r($r);
for($j=0; $j<count($r); $j++){
$r2 = explode("|", $r[$j]);
$r2[$_POST[a.$j]] += 1;
$r3[$j] = implode("|", $r2);
}
$r4 = implode("\n", $r3);
$fp = fopen("./data/r.txt", "wb");
fwrite($fp, $r4);
fclose($fp);
echo "<script>alert('感谢投票!');</script>";
echo "<script>window.location.href='index.php';</script>";
}
?> 
<tr>
<td height="22"></td>
</tr>
<tr>
<td align="center" height="22">
<input type="submit" name="button" id="button" value="提交"> <input type="reset" value='重置' /> <input type="button" onClick="window.open('resault.php');" value='查看结果' /></td>
</tr>
</table>
</form>
</td>
          </tr>
        </table>
        
      </td>
    </tr>
  </table>
  <td width="6"></td>
  <td width="218" class="bian02" valign="top"> 
    <div align="center"> </div>
  </td>
  <table width="800" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="68">
    <tr> 
      <td valign="top">&nbsp;</td>
    </tr>
  </table>
</div>
</body>
</html>
-------------------------------------------------------调查结果页面result.txt---------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>大连民族学院3食堂1楼食堂消费者满意度问卷调查-调查结果</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 10px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head><body bgColor=#999999>
<!--StartFragment-->
<TABLE cellSpacing=0 cellPadding=0 width=570 align=center bgColor=#ffffff 
border=0>
  <TBODY>
    <TR>
      <TD align=middle bgColor=#ffb959 height=43><TABLE width=900 border=0 cellPadding=0 cellSpacing=0>
          <TBODY>
            <TR>
              <TD width="100" height=27><TABLE cellSpacing=0 cellPadding=0 width=100 bgColor=#cc5f24 border=0>
                  <TBODY>
                    <TR>
                      <TD height=3></TD>
                    </TR>
                  </TBODY>
              </TABLE></TD>
              <TD height=27><TABLE cellSpacing=3 cellPadding=0 width=700 bgColor=#cc5f24 border=0>
                  <TBODY>
                    <TR>
                      <TD height=20 align=middle vAlign=bottom bgcolor="#000066" class=w14><div align="center"><FONT style="FONT-SIZE: 18pt" 
color=#ffffff><strong>                      大连民族学院3食堂1楼食堂消费者满意度问卷调查-调查结果
                      </strong></FONT></div></TD>
                    </TR>
                  </TBODY>
              </TABLE></TD>
              <TD width="100" height=27><TABLE cellSpacing=0 cellPadding=0 width=100 bgColor=#cc5f24 border=0>
                  <TBODY>
                    <TR>
                      <TD 
height=3></TD>
                    </TR>
                  </TBODY>
              </TABLE></TD>
            </TR>
          </TBODY>
      </TABLE></TD>
    </TR>
  </TBODY>
</TABLE>
<?php
//读取标题 $t = file_get_contents("./data/t.txt");
$t = explode("\n", $t);//读取问题
$a = file_get_contents("./data/a.txt");
$a = explode("\n", $a);

//读取结果
$r = file_get_contents("./data/r.txt");
$r = explode("\n", $r);

for($i=0; $i<count($t); $i++){
$a1 = explode("|", $a[$i]);
$r1 = explode("|", $r[$i]);
?>
<TABLE width="900" border=0 align=center cellPadding=1 cellSpacing=1 
bgColor=#ffffff>
    <TR bgcolor="#6699FF">
      <TD align=middle colSpan=3>
     <TABLE width="900" height="43" border=0 align="left" cellPadding=0 cellSpacing=8 class=black12>
            <TR>
              <TD vAlign= center bgcolor="#FFCC99"><strong><? echo $t[$i]?></strong></TD>
            </TR>
      </TABLE></TD>
    </TR>  <TR bgcolor="#FF9966">
    <TD width="250" height="38" align="center"><P><FONT style="FONT-SIZE: 15pt" color=#000000><strong>选项</strong></FONT></P></TD>
    <TD align="center"><FONT style="FONT-SIZE: 15pt" color=#000000><strong>比例</strong></FONT></TD>
    <TD width="250" align="center"><FONT style="FONT-SIZE: 15pt" color=#000000><strong>票数</strong></FONT> </TD>
  </TR>
 
<?
$r2 = 0;
for($j=0; $j<count($r1); $j++){
$r2 += $r1[$j];
}
for($k=0; $k<count($a1); $k++){
?>
  <TR bgcolor="#66CCFF">
    <TD width="250" height="35"><FONT style="FONT-SIZE: 12pt; alignment-baseline: middle;" color=#2F2F2F><center><?echo "&nbsp;".$a1[$k]?></center></FONT></TD>
    <TD>
     <TABLE width="400" border=0 cellPadding=0 cellSpacing=0>
<tr><td height="33" align="center"><FONT style="FONT-SIZE: 12pt" color=#2F2F2F><? echo round($r1[$k]*100/$r2, 2)?>%</FONT></td>
</tr>
    </table>
    </TD>
    <TD width="250"><FONT style="FONT-SIZE: 12pt;" color=#2F2F2F><center><?echo $r1[$k]?></center></FONT> </TD>
  </TR>
<?
}
?>
 
  <TR bgColor=#000000>
    <TD colSpan=4 height=2></TD>
  </TR>
</TABLE>
<?
}
?><hr/><TABLE width=900 
border=0 align=center cellPadding=0 cellSpacing=0 bgColor=#ffffff>
  <TBODY>
    <TR>
      <TD height=43 align=middle bgColor=#ffb959></TD>
    </TR>
  </TBODY>
</TABLE>
<!--EndFragment-->
</body>
</html>
---------------------------------------问题文件t.txt------------------------------------------------------------
1、您觉得食堂就餐环境如何?
2、您对食堂工作人员个人卫生是否满意?
3、您觉得食堂就餐秩序如何?
4、您对食堂工作人员服务态度是否满意?
5、您对打饭菜速度是否满意?
6、您对食堂饭菜质量是否满意?
7、您对食堂饭菜的保温是否满意?
8、在学校食堂用餐,您是否有吃不饱的感觉?
9、您认为食堂菜肴品种如何?
10、您对食堂菜肴中哪些品种较满意?
11、您觉得食堂菜肴的味道如何?
12、您觉得食堂的餐具卫生情况如何?
13、您觉得食堂菜肴价格如何?
-----选项a.txt----
A.很好 |B.较好 |C.一般 |D.不好
A.满意 |B.基本满意 |C.不满意
A.很好 |B.较好 |C.一般 |D.不好
A.满意 |B.基本满意 |C.不满意
A.满意 |B.基本满意 |C.不满意
A.满意 |B.基本满意 |C.不满意
A.满意 |B.基本满意 |C.不满意
A.有 |B.没有
A.多 |B.一般 |C.少
A.盖浇饭 |B.自选菜 |C.面食、点心 |D.沙锅 |E.其他
A.好 |B.一般 |C.不好
A.好 |B.一般 |C.不好
A.贵 |B.适当 |C.便宜
------------结果文件r.txt---------
1|2|1|5
23|7|7|17
1|1|1|5|1|1|1
6|17|4
1|1|5|1|1|1|1
13|13|18
1|1|5|1|1|1|1
13|25|33
1|1|5|1|1|1|1
23|33|13|1|3
1|2|4|1|1|1|1
2|3|8
1|1|5|1|1|1|1
31|22|65|1|1|1|1|1|1|1|1|1|1|1