One way is you can use mysql_fetch_assoc() function in a loop like this :
// The array which will store all questions
$questions = array();
while ($row = mysqli_fetch_assoc($result)) {
// Put in the array questions an array per question using mysql fieldsnames
// if a question with main_question_id=2 exists
if (!isset($questions[$row['main_question_id'])) {
//build your question and put it in your array
$questions[$row['main_question_id']] = array(
'question_num' => $row['main_question_number'],
'description' => $row['descritption'],
'obtained_mark' => $row['obtained_mark'],
// etc ...
);
}
}
// Displays description for question 2 for example :
echo $questions[2]['description'];
Then you can build your html (were also doable during first loop)
// Builds head of html table
$html = '<table><tr><th>Question Number</th><th>Desc.</th><th>Mark</th></tr>';
// Builds html content table with another loop
foreach ($questions as $question){
$html .= '<tr>';
$html .= '<td>'.$question["main_number_question"].'</td>';
$html .= '<td>'.$question["description"].'</td>';
$html .= '<td>'.$question["obtained_mark"].'</td>';
$html .= '</tr>';
}
// build the bottom of table
$html .= '</table>;
// Displays all table
echo $html;
Dont forget to check doc and comments behind her here :
http://php.net/mysqli_fetch_assoc
You can also use
http://php.net/mysqli_fetch_array
Cheers,