while ($question = $questions_result->fetch_object()) {
                        if (!isset($set[(int) $question->question_id])) {
                            $break = true;
                            break;
                        }
                    }
                    if (!$break) {
                        $i = 1;
                        foreach ($set as $k => $v) {
                            // echo 'UPDATE question SET question_num='.$i.' WHERE question_id='.$k.' AND question_questionnaire_id='.$questionnaire_id;
                            $_MYSQLI->query('UPDATE question SET question_num=' . $i . ' WHERE question_id=' . $k . ' AND question_questionnaire_id=' . $questionnaire_id);
                            $i++;
                        }
                        $ajax->data = $orders;
                    } else {
                        $ajax->setError("query_error: order argument fail, an id does not exist in database");
                    }
                } else {
                    $ajax->setError("query_error: order argument fail, not the same entry number that in database");
                }
            } else {
                $ajax->setError("query_error: questionnaire does not exist or you are not the owner");
            }
        } else {
            $ajax->setError("query_error: bad arguments");
        }
    } else {
        $ajax->setError("query_error: missing POST arguments");
    }
} else {
    $ajax->setError("not_logged");
Example #2
0
						FROM question q
						JOIN choice c ON c.choice_question_id = q.question_id
						INNER JOIN answer a ON a.answer_choice_id = c.choice_id
						INNER JOIN user u ON u.user_id = a.answer_student_user_id
						WHERE question_questionnaire_id = ' . $_MYSQLI->real_escape_string($_GET["questionnaire_id"]) . '
						GROUP BY answer_student_user_id, choice_id';
            $answer_result = $_MYSQLI->query($query);
            while ($answer = $answer_result->fetch_object()) {
                if (isset($ajax->data["questions"][$answer->question_id])) {
                    if (!isset($ajax->data["answers"][$answer->answer_student_user_id])) {
                        $ajax->data["answers"][$answer->answer_student_user_id] = array("identity" => $answer->user_identity, "score" => $question_keys);
                    }
                    if (isset($ajax->data["questions"][$answer->question_id]["choices"][$answer->choice_id])) {
                        if ($ajax->data["questions"][$answer->question_id]["choices"][$answer->choice_id]["correct"]) {
                            $ajax->data["answers"][$answer->answer_student_user_id]["score"][$answer->question_id]["correct"]++;
                        } else {
                            $ajax->data["answers"][$answer->answer_student_user_id]["score"][$answer->question_id]["uncorrect"]++;
                        }
                    }
                }
            }
        } else {
            $ajax->setError("questionnaire not exists");
        }
    } else {
        $ajax->setError("query_error: questionnaire_id missing");
    }
} else {
    $ajax->setError("not_logged");
}
$ajax->out();