I want to make if else in php but i don't know how
Get the solution ↓↓↓I want to make if else using 'score'. But i don't know how to code that,
for example ifscore = 10
you will pass the test, and ifscore = 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);
}
}
?>
Answer
Solution:
<?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
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: trying to access array offset on value of type bool
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.