I am creating a multiple choice quiz game with PHP and Javascript. Questions can have 2 to 6 answers. I have been using the PHP queries in the code below to get arrays of the questions of a quiz, and the answers for each questions.
I now want to use this data in Javascript, and want to make it so each time a user clicks next question, a question and corresponding answers are displayed.
I think (but am not sure) that the best way to do this is to combine the arrays into one where the question array contains the answers arrays before converting to a javascript array.
Is this really the way I should do this, and if so how do I do so?
$thisquizid = $_POST['quizidvalue'];
for ($j = 0; $j < $questionrows; ++$j)
{
$questionresult = pg_fetch_array($questionquery);
$answerquery = pg_query($db_handle, "SELECT * FROM answer WHERE questionid = '$questionresult[0]'");
$answerrows = pg_num_rows($answerquery);
for ($i = 0; $i < $answerrows; ++$i)
{
$answerresult = pg_fetch_array($answerquery);
}
}