<?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) {}
空空的><卡關好幾天了,麻煩板上高手救助。