好的。我幾乎明白了。我有一個循環問題。我無法讓PHP方面坐下來等待用戶的迴應。我嘗試isset,它仍然繼續。我在這裏粘貼我的代碼。希望沒關係。 excel電子表格基本上是從第4行開始的,作爲你的多個選擇,然後你選擇它,找到你選擇的列,然後連續詢問下一行問題...我很抱歉,我知道這是新手鎮但我真的很感激反饋。用戶輸入PHP中的for循環
<HTML>
<HEAD>
<title>
</title>
</head>
<body>
<?php
// include class file
include 'Excel/reader.php';
// initialize reader object
$excel = new Spreadsheet_Excel_Reader();
// read spreadsheet data
$excel->read('Question-Flow.xls');
$x = 4; //Row
$y = 0; //Column @ 0 for 1st iteration
$questions = array(); //Stores questions and ends in 'STOP'
//Iterates down a row until $cell='SUBMIT'
do {
//Populates $questions() and iterates until $cell='STOP'
do {
$y++;
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
if ($cell){
//Populates $questions array with active cells
array_push($questions, $cell);
}
} while ($cell != 'STOP');
for ($i=0; $i < count($questions)-1; $i++){
//echo "<input type=radio name=$i value=\"".$questions[$i]."\">".$questions[$i]."<br>";
?>
<HTML><BODY>
<form action="index.php" method="post">
<input type=submit name=choice value=<?php echo $questions[$i]; ?> style="width: 100px; height: 100px;"><br>
</form>
</BODY></html>
<?php
//Move $cell back one from 'STOP'
$y--;
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
$choice = $_POST['choice'];
if(isset($_POST['choice'])){
echo $choice;
echo $cell;
echo $x;
echo $y;
}
}
while($choice != $cell){
//Iterate back to find $choice
$y--;
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
}
//Moves to next row of Questions
$x++;
//Populates $cell with 'SUBMIT' or prompts next question
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
} while ($cell != 'SUBMIT');
?>
</body>
</html>
我迷路了。我是PHP新手,JavaScript,HTML,所以請原諒愚蠢的問題。我有這個數組已經從excel文件中填充了字符串。打印看起來像
Array ([0] => Question1 [1] => Question2 [2] => Question3 [3] => STOP)
我需要每個這些價值的的呈現給用戶的問題,並讓他們二者之間做出選擇。然後,我需要循環回去,並從excel中輸入新值(這已全部完成)並返回給該數組,然後再問他們新的問題。我需要將他們的答案存儲到他們選擇的「單元格」的excel循環中。這就像問題的分支樹。
如果我可以把某種類型的輸入形式放到下面的for循環中,那麼它會正常工作嗎?雖然不會採取。
for ($i=0; $i < count($questions); $i++){
echo $i; //echo'd just to see the count and it's correct
}
請不要提供w3schools的參考資料。那裏的信息經常過時或無效。 – webnoob