我基本上要做的是,如果用户得分&gt; = 2,则显示“竖起拇指”,如果用户得分<1则显示“竖起拇指”。 2
这是我试图使用的代码..
<?php
//Recieves form..Form ID
$fid = $_GET['id'];
//Recieves answers
$answer1= $_POST['answerOne'];
$answer2= $_POST['answerTwo'];
$answer3= $_POST['answerThree'];
$score=0;
?>
<?php //Gets thumbs up if did well, gets thumbs down if not so good
if ($score>=2){
echo "<center><img src='Images/thumbsup.png' height='295' width='295' /> </center>";
}
elseif ($score<2) {
echo "<center><img src='Images/thumbsdown.png' height='295' width='295' /> </center>";
}
?>
<body>
<!--Answers for Quiz 1-->
<?php
if ($fid == 1){
if ($answer1 == "B") {$score++;}
if ($answer2 == "B") {$score++;}
if ($answer3 == "A") {$score++;}
}
?>
<?php
if ($fid == 1){
echo "
<p id='YourScore'> Your score is: </p>
<p id='YourScore'>$score/3 correct answered </p>";}
?>
它会一直显示出“大拇指朝下”。我认为这是因为$ score等于0,并且在将分数添加为用于定义是否放弃竖起大拇指的值之后,其未执行的操作是使用递增的值。
任何帮助将不胜感激。
答案 0 :(得分:0)
那是因为你没有检查答案因此得分总是为0而elseif ($score<2)
总是为真。
你必须在打印'拇指'
之前检查答案是否正确答案 1 :(得分:0)
正如我的评论所述:你在拇指后计算得分,所以转过身来:
<?php
//Recieves form..Form ID
$fid = $_GET['id'];
//Recieves answers
$answer1= $_POST['answerOne'];
$answer2= $_POST['answerTwo'];
$answer3= $_POST['answerThree'];
$score=0;
?>
<body>
<div id="Wrapper">
<div id="Container">
<!--Answers for Quiz 1-->
<?php
if ($fid == 1) {
if ($answer1 == "B") {$score++;}
if ($answer2 == "B") {$score++;}
if ($answer3 == "A") {$score++;}
}
?>
<?php
//Gets thumbs up if did well, gets thumbs down if not so good
if ($score >= 2) {
echo "<img src='Images/thumbsup.png' height='295' width='295' /> ";
}
elseif ($score < 2) {
echo "<img src='Images/thumbsdown.png' height='295' width='295' /> ";
}
if ($fid == 1) {
echo "<p id='YourScore'> Your score is: </p>
<p id='YourScore'>$score/3 correct answered </p>";
}
?>