Turning multiple PHP arrays into one array ready for conversion to Javascript
Running a SQL statement in a loop is in general a bad idea. Depending on your $questionsrow you might send a lot of not needed requests.

In relation to MECUs hint you could use something like:

$questions=array();
//add constrains to select only some questions or sort the answers
$result=...query($db_handle, "SELECT * FROM answer");
while ($row=...fetch_array($result))
{
    $qid=$row['questionid'];
    if (!isset($questions[$qid])) =array(); //create subarray if new question
    $questions[$qid][]=$row //append a new element to the question array
}
$json=json_encode($questions);


I.e. $questions[1] will contain a array with all your answers to question 1. The sorting of the answers can be moved to SQL query, also if you don't need all fields you can restrict this in the SQL and don't need to take care of this in your PHP.