<?php
date_default_timeZone_set('Asia/Taipei');
include ("configure.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>后天体质判定问卷</title>
<meta name="keywords" content="关键字, 以逗号隔开">
<meta name="description" content="网站叙述">
</head>
<body>
<div align="left">
<form method="POST" action="qnsn.php">
<table align="left" width="" height="" border="0">
<tr>
<td><div align="left"><span style='font-size:36.0pt;
font-family:标楷体;color:black'><span class="style1">后天体质判定问卷
</span></span></div></td>
</tr>
<tr>
<td><blockquote>
</br>
<p align="left" class="style2"> 0 分为三个月内没发生过</p>
<p align="left" class="style2"> 1分为三个月内发生过 1-3 次</p>
<p align="left" class="style2"> 2分为三个月内发生过 4-6 次</p>
<p align="left" class="style2"> 3 分为三个月内发生过 7-9 次</p>
<p align="left" class="style2"> 4 分为三个月内发生过 10 次以上</p>
<p align="left" class="style2"> 非常感谢您的作答! </p>
<p align="left" class="style2"> 测验者输入姓名:<input type="text"
name="name" size="10" maxlength="10" value=""></p>
</blockquote></td>
</tr>
</table>
<hr size="3" align="center" width="100%" color="#00FFFF">
</div>
<?php
$link = mysql_connect($hostname, $username, $password)OR die("Unable to
connect to database");
if ($link)
mysql_select_db($database);
else
die("Unable to select database");
mysql_query("SET NAMES utf8");
$query = "SELECT * FROM `questionnairetable1` ORDER BY `number`
ASC,`physique` ASC,`QNSN` ASC;";
$result = mysql_query($query) or die("Connect DB Table Error!");
$number=0;
while($row=mysql_fetch_array($result))
{
$number++;
(int)$number;
echo "<p align=\"left\">";
echo "<table align=\"left\" border=\"0\">";
echo "<tr
align=\"center\"><td>".nl2br($row["number"])."</td><td>".nl2br($row["physique"])."</td><td>".nl2br($row["QNSN"])."</td>
<td colspan=\"1\">
<input type=\"radio\" name=\"q$number\" value=\"0\">0
<input type=\"radio\" name=\"q$number\" value=\"1\">1
<input type=\"radio\" name=\"q$number\" value=\"2\">2
<input type=\"radio\" name=\"q$number\" value=\"3\">3
<input type=\"radio\" name=\"q$number\" value=\"4\">4</td>
</tr>";
echo "</br>";
echo "</p>";
switch($number){
case 7:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 14 :
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 21:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 26:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 34:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 41:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 48:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 54:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 61:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
case 67:
echo "<hr size=\"3\" align=\"center\" width=\"100%\" color=\"#00FFFF\">";
break;
}
}
echo "</table>";
// 释放结果集($result)所占用的内存。(若无释放,程式可能会错误,尤其是用
"SELECT ..."的时候)
mysql_free_result($result);
// 关闭与MySQL数据库的连线,若用mysql_pconnect()则不需要此行
mysql_close($link);
?>
<hr size="3" align="center" width="100%" color="#00FFFF">
<input type="submit" name="submit" value="送出">
<input type="reset" name="reset" value="重新填写">
<?php
if((isset($_POST["submit"]))&&(isset($_POST["name"])))
{
$q=array();
for($j=1;$j<=66;$j++){
if(isset($_POST["q$j"])){
$q[$j]=($_POST["q$j"]);
echo "$q[$j]";
}
}
echo "</br>";
var_dump($_POST);
echo "</br>";
var_dump($q);
echo "</br>";
}
?>
</form>
</body>
</html>
程式码全部如上
请益关于抓到的值,我打算做某几题到某几题的总合
总题数有66题~
但下半段PHP一直无法把抓到的值存到新的q[]阵列里面
参考板上旧文var_dump($_POST);的值如下
array(8) {
["name"]=>
string(7) "2312342"
["q_1"]=>
string(1) "1"
["q_2"]=>
string(1) "1"
["q_3"]=>
string(1) "1"
["q_4"]=>
string(1) "1"
["q_5"]=>
string(1) "1"
["q_6"]=>
string(1) "1"
["submit"]=>
string(6) "送出"
但是var_dump($q);如下
array(0) {}
空空的><卡关好几天了,麻烦板上高手救助。