Combine 2 arrays by matching the same foreign key

后端 未结 2 1884
死守一世寂寞
死守一世寂寞 2021-01-28 23:26

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

2条回答
  •  走了就别回头了
    2021-01-29 00:00

    Can you try following code:

    $sql = "select q.id, q.question, a.aswer from question_table q inner join answer_table a ON q.id = a.id_question”;
    $resultPertanyaan = mysqli_query($con, $sql);
    
    while($rowQuery= mysqli_fetch_array($resultPertanyaan)){
       $array_result[]= 
    array('id'=>$rowQuery['id’],’question’=>$rowQuery['question'], 'answer' => $rowQuery['aswer']);
    }
    

提交回复
热议问题