Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我想在php中生成if-else,但我不';我不知道怎么做_Php - Fatal编程技术网

我想在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
}
?>