lundi 4 octobre 2021

insert value of checkboxes in multiple rows in single column using php

$counter = 1;
if($result){
    foreach($option_marks as $option => $value){
            if($value == 1){
                $is_correct = 1;
            }else{
                $is_correct = 0;
            }
            //Second Query for Choices Table
            $query = "INSERT INTO options (";
            $query .= "question_number,choice,correct)";
            $query .= " VALUES (";
            $query .=  "'{$question_number}','{$choice[$counter]}','{$is_correct}'";
            $query .= ")";
            $counter++;

            $insert_row = mysqli_query($connection,$query);
    }
    
    $message = "Checkboxes question added successfully";
}
$query = "SELECT count(correct) FROM options where question_number=$question_number AND correct=1";
$total_correct = mysqli_num_rows(mysqli_query($connection,$query));
$dividedmarks=$question_marks/$total_correct;

$query="INSERT into options(mark) VALUES('$dividedmarks') where question_number=$question_number AND correct=1";

}

I want to insert $dividedmarks value in multiple rows of options table column marks where correct is equal to one. The value of $divided marks should be calculated after the values of first query above are inserted. its value comes from checkboxes.




Aucun commentaire:

Enregistrer un commentaire