$quests = [];
foreach ($bd as $bd_element) {
$quests[$bd_element['id_question']][] = $bd_element['id'];
}
$a = 0;
foreach ($quests as $id_quest => $ans) {
$is = true;
foreach ($ans as $an) {
if (array_search($an, $answer[$id_quest]) === false) $is = false;
}
if ($is) $a++;
}
$quests = [];
foreach ($bd as $bd_element) {
$quests[$bd_element['id_question']][] = $bd_element['id'];
}
$a = 0;
foreach ($quests as $id_quest => $ans) {
$is = true;
foreach ($ans as $an) {
if (array_search($an, $answer[$id_quest]) === false) $is = false;
}
foreach ($answer[$id_quest] as $answer) {
if (array_search($answer, $ans) === false) $is = false;
}
if ($is) $a++;
}
foreach ($answer as $id_quest => $answers) {
$is = true;
foreach ($bd as $bd_element) {
$is_bd = true;
if ($bd_element['id_question'] != $id_quest) continue;
if (array_search($bd_element['id'], $answers) === false) $is = false;
}
if ($is) $a++;
}
if ($test) {
$answer = [
1 => [1,3],
2 => [4],
];
$bd = [
[
'id' => 2,
'id_question' => 1,
'correct_answer' => 1,
],
[
'id' => 3,
'id_question' => 1,
'correct_answer' => 1,
],
[
'id' => 4,
'id_question' => 2,
'correct_answer' => 1,
],
];
$a = 0;
foreach ($answer as $id_quest => $answers) {
$is = true;
foreach ($answers as $id_answer) {
$is_a = false;
foreach ($bd as $bd_element) {
if ($bd_element['id_question'] != $id_quest) continue;
if ($id_answer == $bd_element['id']) {
$is_a = true;
}
}
if (!$is_a) $is = false;
}
if ($is) $a++;
}
echo 'Правильных ответов: '.$a.'<br>';
exit;
}
// Правильных ответов: 1
$a = 0;
foreach ($answer as $id_quest => $answers) {
$is = true;
foreach ($answers as $id_answer) {
$is_a = false;
foreach ($bd as $bd_element) {
if ($bd_element['id_question'] != $id_quest) continue;
if ($id_answer == $bd_element['id']) {
$is_a = true;
}
}
if (!$is_a) $is = false;
}
if ($is) $a++;
}
$a = 0;
foreach ($answer as $id_quest => $answers) {
foreach ($answers as $id_answer) {
foreach ($bd as $bd_element) {
if ($bd_element['id_question'] == $id_quest and $id_answer == $bd_element['id']){
$a++;
echo 'id_aswer: '.$id_answer.' - верно<br>';
} else {
echo 'id_aswer: '.$id_answer.' - не верно<br>';
}
}
}
}
if ($test) {
$answer = [
1 => [9,3],
2 => [4],
];
$bd = [
[
'id' => 2,
'id_question' => 1,
'correct_answer' => 1,
],
[
'id' => 3,
'id_question' => 1,
'correct_answer' => 1,
],
[
'id' => 4,
'id_question' => 2,
'correct_answer' => 1,
],
];
$a = 0;
foreach ($answer as $id_quest => $answers) {
$is = false;
foreach ($answers as $id_answer) {
foreach ($bd as $bd_element) {
if ($bd_element['id_question'] == $id_quest and $id_answer == $bd_element['id']) $is = true;
}
}
if ($is) $a++;
}
echo 'Правильных ответов: '.$a.'<br>';
exit;
}
$answer = $_POST['answer'];
$bd = $pdo->query('SELECT * FROM answers WHERE correct_answer = 1');
$a = 0;
foreach ($answer as $id_quest => $answers) {
$is = false;
foreach ($answers as $id_answer) {
foreach ($bd as $bd_element) {
if ($bd_element['id_question'] == $id_quest and $id_answer == $bd_element['id']) $is = true;
}
}
if ($is) $a++;
}
echo 'Правильных ответов: '.$a.'<br>';
<?
$movie_id = $_GET['movie_id'];
$movies = ['id_видео' => 'путь до файла видео'];
?>
<video class=" " controls="controls" width="100%" >
<source src="<?= $movies[$movie_id] ?>" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
</video>