我想在php中生成if-else,但我不';我不知道怎么做
我想用“分数”来判断是否还有其他问题。但我不知道怎么编码, 例如,如果我想在php中生成if-else,但我不';我不知道怎么做,php,Php,我想用“分数”来判断是否还有其他问题。但我不知道怎么编码, 例如,如果score=10您将通过测试,如果score=7您将无法通过测试 我已经试了4天了,但是我还没有找到解决办法,我希望有人能帮助我 <?php session_start(); ?> <?php include 'database.php'; ?> <?php //Check to see if score is set_error_handler if(!isset($_S
score=10
您将通过测试,如果score=7
您将无法通过测试
我已经试了4天了,但是我还没有找到解决办法,我希望有人能帮助我
<?php session_start(); ?>
<?php include 'database.php'; ?>
<?php
//Check to see if score is set_error_handler
if(!isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
}
if($_POST) {
$number = $_POST['number'];
$selected_choice = $_POST['choice'];
$next = $number+1;
/*
* Get total questions
*/
$query = "SELECT * FROM `questions_tak`";
//Get result
$results = $mysqli->query($query) or die($mysqli->error.__LINE__);
$total = $results->num_rows;
/*
* Get correct choice
*/
$query = "SELECT * FROM `choices_tak`
WHERE question_number = $number AND is_correct = 1";
//Get result
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
//Get row
$row = $result->fetch_assoc();
//Set correct choice
$correct_choice = $row['id'];
//Compare
if($correct_choice == $selected_choice) {
//Answer is correct
$_SESSION['score']++;
}
//Check if last question
if($number == $total) {
header("Location: final.php");
exit();
} else {
header("Location: question.php?n=".$next);
}
}
?>
有关更多详细信息,请访问您似乎已经在代码中使用了
if/else
?你还不明白什么?尝试编写代码的示例会很有帮助。
<?php
//If you have a score variable
$score=0; //Your value
//If Score 10 or greater than 10
if($score>=10){
echo "Passed";
}else{
echo "Failed"; //If score less than 10
}
?>