gpt4 book ai didi

php选择选项编程

转载 作者:行者123 更新时间:2023-11-29 12:07:24 24 4
gpt4 key购买 nike

我如何在 php 中判断他们是否用 YES 回答问题 1,2,3,5,6 并给出“答案 A”如果他们对问题 1、3、5、10、12 的回答为"is",则给出“答案 B”其他情况,给出“答案C”

    <form action="questions".php" method="POST">
<p>1.Question1?</p>
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
<p>2.Question2?</p>
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
<p>3.Question3?</p>
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
<p>4.Question4?</p>
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
<p>5.Question5?</p>
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
<p>6.Question6?</p>
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
7.Question7?
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
8.Question8?
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
9.Questione9?
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
10.Question10?
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
11.Question11?
<p><select> <option value="YES">YES</option> <option value="NO">NO</option> </select></p>
<input name="submit" type="submit" value="submit" /> </form>

最佳答案

下面是如何使用选择来完成此操作的示例。我认为单选按钮在这里会更好。

<form method="POST" action="questions.php">
<p>1.Question1?</p>
<p>
<select name="questions[1]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
<p>2.Question2?</p>
<p>
<select name="questions[2]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
<p>3.Question3?</p>
<p>
<select name="questions[3]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
<p>4.Question4?</p>
<p>
<select name="questions[4]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
<p>5.Question5?</p>
<p>
<select name="questions[5]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
<p>6.Question6?</p>
<p>
<select name="questions[6]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
7.Question7?
<p>
<select name="questions[7]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
8.Question8?
<p>
<select name="questions[8]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
9.Questione9?
<p>
<select name="questions[9]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
10.Question10?
<p>
<select name="questions[10]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
11.Question11?
<p>
<select name="questions[11]">
<option value="YES">YES</option>
<option value="NO">NO</option>
</select>
</p>
<input name="submit" type="submit" value="submit" />
</form>

然后在 PHP 端进行处理...(我也不确定你的条件如何工作,这是一种可以完成的方法。)

foreach($_POST['questions'] as $key => $question) {
switch($key) {
case 1:
case 2:
case 3:
case 5:
case 6:
if($question == 'YES') {
echo 'the answer A';
} else {
echo 'the answer C';
}
break;
case 4:
case 7:
case 8:
case 9:
case 10:
case 11:
if($question == 'YES') {
echo 'the answer B';
} else {
echo 'the answer C';
}
break;
}
}

输出:

Question #1=YES<br />Question #2=NO<br />Question #3=NO<br />Question #4=NO<br />Question #5=NO<br />Question #6=NO<br />Question #7=NO<br />Question #8=NO<br />Question #9=NO<br />Question #10=NO<br />Question #11=NO<br />

关于php选择选项编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31247885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com