简体   繁体   中英

I want to make if else in php but i don't know how

I want to make if else using 'score'. But i don't know how to code that, for example if score = 10 you will pass the test, and if score = 7 you will not pass the test.

I have trying for 4 days, but I haven't find the solution, I hope someone can help me.

  <?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);
        }
    }
?>
   <?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
}
?>

For more details visit https://www.w3schools.com/php/php_if_else.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM