I have 2 tables: questions, answers.
questionshas the fields: questionId, title, category,
correctAnswerID, urlanswershas the fields: answerId, questionId, text
I have this function:
$result = query("SELECT * FROM questions INNER JOIN answers ON questions.questionId=answers.questionId");
it returns the questions 4 times, and every time with different answer.
I want an array that contains an array of questions, and every question will has an array of related answers.
Every question has 4 possible answers, and every question has the correct answer ID.
Thanks in advance.
MySQL cannot return such a multi-dimensional array natively, only a 2 dimensional array where level one is the rows, and level-two are the columns.
You’ll have to iterate the result set and build the array yourself.
In PDO, you’d do something like this:
Which gives me the following result (yours would probably look different):