I have 2 table, that is a question_table and answer_table
the structure is like this :
And I have a JSON array that I got from question_table and answer_table using php like this.
// to get the question
$pertanyaan = "select * from question_table”;
$resultPertanyaan = mysqli_query($con, $pertanyaan);
while($rowQuery= mysqli_fetch_array($resultPertanyaan)){
$array_question[]=
array('id'=>$rowQuery['id’],’question’=>$rowQuery['question']);
}
and the result is like this
array_question :
[
{
"id": "8",
“question”: "Shop sign/billboard "
},
{
"id": "10",
"question": "Pylon"
},
{
"id": “11”,
“question”: "Banner”
},
{
"id": "12”,
"question": “Sport”
},
{
"id": “14”,
“question”: “Matic "
},
{
"id": "16”,
"question": “Cub”
}
]
To get the answer
$jawaban = "select * from answer_table”;
$resultJawaban = mysqli_query($con, $jawaban);
while($rowQuery= mysqli_fetch_array($resultJawaban)){
$array_answer[]=
array('id'=>$rowQuery['id'],'remark'=>$rowQuery['remark'],'item'=>$rowQuery['item']);
}
and the result like this
array_answer :
[
{
"id": "1b9fa84e-0f2f-11e9-b673-005056be36b2",
“answer”: "3",
“id_question”: "16"
},
{
"id": "bc82c3fd-0f2e-11e9-b673-005056be36b2",
"answer": "1",
"id_question": "11"
},
{
"id": "cc9363f1-0f2e-11e9-b673-005056be36b2",
"answer": "3",
"id_question": "12"
},
{
"id": "f1dfa8b5-0f2e-11e9-b673-005056be36b2",
"answer": "1",
"id_question": "14"
}
]
I want to combine array_answer with array_question, which results like this:
array_result :
[
{
"id": "8",
“question”: "Shop sign/billboard ",
“asnwer” : null
},
{
"id": "10",
"question": "Pylon”,
“asnwer” : null
},
{
"id": “11”,
“question”: "Banner”,
“asnwer” : “1”
},
{
"id": "12”,
"question": “Sport”,
“answer” : “3”
},
{
"id": “14”,
“question”: “Matic “,
“answer” : “1”
},
{
"id": "16”,
"question": “Cub”,
“answer” : “3”
}
]
How do I get array_result like I expected? Please help me, Thank you