// Zavrsen test prikazi rezultat
//if ( !empty($_GET['ime']) ) {
if ((!empty($_POST['radio'])) || (!empty($_POST['ime']) || $glasao)) {
//var_dump($_POST['radio']);
if (!empty($_POST['radio'])) {
$rezultat_kviza = $_POST['radio'];
$odgovori_pod0=0;
$odgovori_pod1=0;
$odgovori_pod2=0;
$odgovori_pod3=0;
$odgovori_pod4=0;
foreach ($rezultat_kviza as $key => $odgovor) {
//ON DUPLICATE KEY
$sql_q = MySql_Query("SELECT * FROM answers WHERE quiz_id = '$q_id' AND question_number = '$key'");
if (!mysql_num_rows($sql_q)) {
$sql_i="INSERT INTO answers (id, quiz_id, question_number, odgovor_".intval($odgovor).") VALUES (NULL, '{$q_id}', '{$key}', '1') ";
}else{
$sql_i="UPDATE answers SET odgovor_".intval($odgovor)."=odgovor_".intval($odgovor)."+1 WHERE quiz_id='{$q_id}' AND question_number = '$key'";
}
$result_i = mysql_query($sql_i, $db);
//echo $key." - ".$odgovor."
";
}
}
if ( ($glasao) || (!empty($_POST['radio'])) ) {
echo "
Rezultati ankete
";
$result_r = mysql_query($sql, $db);
$pitanje_anketa = array();
$odgovori_anketa = array();
$brojac=1;
while ($print_result_r = mysql_fetch_array($result_r)) {
$pitanje_anketa[$brojac] = $print_result_r['question'];
$odgovori_anketa[$brojac] = array("0", $print_result_r['answer1'], $print_result_r['answer2'],$print_result_r['answer3'],$print_result_r['answer4']);
$brojac++;
}
$sql_get="SELECT * FROM answers WHERE quiz_id='{$q_id}' ORDER BY question_number ASC";
$result_get = mysql_query($sql_get, $db);
while ($anketa_result = mysql_fetch_assoc($result_get)) {
$ukupno=0;
$ukupno=$anketa_result['odgovor_1']+$anketa_result['odgovor_2']+$anketa_result['odgovor_3']+$anketa_result['odgovor_4'];
//echo "Odgovora na pitanje {$anketa_result['question_number']} ukupno: $ukupno
";
echo "
".$pitanje_anketa[ $anketa_result['question_number'] ]."
";// ukupno: $ukupno
";
//echo '
';
for ($i=1; $i<=4; $i++) {
if ($anketa_result['odgovor_'.(string)$i] !== '0') {
$procenat = $anketa_result['odgovor_'.(string)$i] / $ukupno * 100;
//echo "Odgovor pod {$i} $procenat %
";
printf($i.". ".$odgovori_anketa[$anketa_result['question_number']][$i]." - %.2f %%
", $procenat);
}
}
//echo '
';
echo '';
}
unset($pitanje_anketa);
unset($odgovori_anketa);
}
//echo "
Povratak na anketu: Home
";
$number_of_question = 0;
} else {
?>
}
?>