好的。我差点明白了。我有一个循环问题。我无法让 PHP 端坐下来等待用户响应。我尝试isset,它仍然继续。我在这里粘贴我的代码。希望没关系。它从基本上row = 4中提取的excel电子表格作为您的多项选择,然后您选择,它会找到您选择的列并向下一行询问下一行问题......对不起,我知道这是菜鸟镇,但我非常感谢您的反馈。
<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
}