I am currently in the process of making a quiz, with the table format:
| id | question | option1 | option2 | option3 | answer |
--------------------------------------------------------
| 1 | What is my name? | Dave | Bob | Charles | Linda |
I am trying to verify user's answers and I'm not quite sure how to go about it. I am a bit stumped using the foreach loop to assign array values to other arrays. The following code within matresult.php incorrect but it should show what I am trying to achieve:
Within matquiz.php I have
//MySql query to select all data from matquiz table
$query="SELECT * FROM MatQuiz";
//Assign the query to a result variable
$result = mysql_query($query, $connect);
while($row = mysql_fetch_assoc($result)){
CODE
}
Within matresult.php I have
$array3 = array();
$array4 = array();
$array5 = array();
$array6 = array();
$array7 = array();
$array8 = array();
$finalresults = array($row['ID'], $row['question'], $row['option1'], $row['option2'], $row['option3'], $row['answer']);
foreach($finalresults as $value){
array_push($array3, $value['ID']); //ID
array_push($array4, $value['question']); //question
array_push($array5, $value['option1']); //op1
array_push($array6, $value['option2']); //op2
array_push($array7, $value['option3']); //op3
array_push($array8, $value['answer']); //answer
}
What I am trying to achieve is to push each $finalresults array value into 6 seperate arrays, and do this for 5 questions/rows.
So for example, I want array3 to hold all 5 question IDs. [1,2,3,4,5] and I would like array4 to hold all 5 questions etc.
I am aware that the syntax within the foreach loop is wrong but this is my question to you, how would I go about achieving this?