The assessment with posed problems and their respective text-only answer options works without problems for example:
a1 a2 a3 a4 answer
1/9 19/5 12/1 1/4 19/5
The columns a1, a2, a3, a4
are the options and the column answer
has the correct answer, using JSON this information is generated:
[
'name' => 'respuesta_1',
'question' => 'Planteamiento del problema?',
'alternatives' => [1/9, 19/5, 12/1, 1/4],
'answer' => 19/5,
],
Where I do select the correct option, 19/5
it qualifies me as it is, earning me 1 point.
But already in the case where there are options where I cannot add text but images in the columns a1, a2, a3, a4
, the PHP code cannot detect whether or not the selected option is correct or incorrect, even more so when the correct image response has been selected. evaluates it as incorrect.
For example, in this image case, I had the following data recorded:
a1
<img src="https://i.imgur.com/HdfyxwC.png" width="18">
a2
<img src="https://i.imgur.com/4QIRf6R.png" width="18">
a3
<img src="https://i.imgur.com/fSNMF2l.png" width="18">
a4
<img src="https://i.imgur.com/DMTiaxk.png" width="18">
answer
<img src="https://i.imgur.com/fSNMF2l.png" width="18">
How can I solve this evaluation problem, can you explain how I can make the qualifier work for both text and image.
The PHP code that performs this evaluation is as follows:
results-evaluations.php
$sql = "SELECT * FROM quiz";
$result = $con->query($sql);
while($row = mysqli_fetch_assoc($result)) {
$answers[] = [
'name' => 'respuesta_'.$row["id_question"],
'question' => $row["question"],
'alternatives' => [$row["a1"], $row["a2"],$row["a3"],$row["a4"]],
'answer' => $row["answer"]
];
}
$questions = [];
foreach($answers as $index => $answer) {
$questions[]=$answer;
$questions[$index]['answer']=null;
}
$final=[];
// Hay que evaluar
if(isset($_POST['student'])) {
$student = $_POST['student'];
$result=[];
$qualify_score = 0;
$top_score = sizeof($answers);
foreach($answers as $index => $answer) {
$result_quote=['index'=>$index];
$result_quote['question']=$answer['question'];
$result_quote['your_answer']=isset($_POST[$answer['name']])? $_POST[$answer['name']] : 'N/A';
$result_quote['correct_answer']= $answer['answer'];
$result_quote['qualify_score']=($result_quote['your_answer']==$result_quote['correct_answer'])? 1:0;
$qualify_score+=$result_quote['qualify_score'];
$result[]=$result_quote;
}
$final=[
'student'=>$student,
'result'=>$result,
'qualify_score'=>$qualify_score.' / '.$top_score
];
}
echo json_encode($final);
At the moment I understand that the code is vulnerable, I will solve this later in the subject of object-oriented and security.
Jacks here I leave you an example, to see if what I want to explain to you is better understood.
The logic that follows is very simple. I am going to intelligently use those
id
of each element to identify if it is a text (txt
) or an image (img
). On clicking the button my JS code creates a variabledata
that could be sent to the server.For example, if the
B
text option and theC
image option are selected, we will send this information to the server:Simply by the nomenclature, we already know that:
a2
, for a reason it has the idtxt2
...a3
, for a reason it has the idimg3
...With these data, the server will already know how it has to work.
I don't know if that's exactly your scenario, but the answer shows a way to use our identifiers cleverly to know what type of element is being clicked and which response it corresponds to.