Im working on a quizz with php mysql and javascript that consist in an array that stores the information in the following order: Question,option a, option b, option c, option d, option e, option f, and Im using a several functions to store the score and progress of the user, but do not have a clue on how to store this information in a database, so an administration is able to consult it in a further time. Here are the functions that are used in the program:
function populate() {
if(quiz.isEnded()) {
showScores();
}
else {
// show question
var element = document.getElementById("question");
element.innerHTML = quiz.getQuestionIndex().text;
// show options
var choices = quiz.getQuestionIndex().choices;
for(var i = 0; i < choices.length; i++) {
var element = document.getElementById("choice" + i);
element.innerHTML = choices[i];
guess("bt" + i, choices[i]);
}
showProgress();
}
};
function guess(id, guess) {
var button = document.getElementById(id);
button.onclick = function() {
quiz.guess(guess);
populate();
}
};
function showProgress() {
var currentQuestionNumber = quiz.questionIndex + 1;
var element = document.getElementById("progress");
element.innerHTML = "Question number " + currentQuestionNumber + " de " + quiz.questions.length;
};
function showScores() {
var gameOverHTML = "<h1>The test has ended</h1>";
gameOverHTML += "<h2 id='score'> Result: " + quiz.score + "</h2>";
var element = document.getElementById("quiz");
element.innerHTML = gameOverHTML;