Eine Möglichkeit ist, dass Sie mysql_fetch_assoc() Funktion in einer Schleife wie diese verwenden:
// 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'];
Dann können Sie Ihre HTML bauen (waren auch machbar während erste Schleife)
// 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;
Vergessen Sie nicht, Um Doc und Kommentare hinter ihr hier zu überprüfen: http://php.net/mysqli_fetch_assoc
Sie können auch verwenden
Cheers,
Für den Anfang: http://php.net/manual/en/pdostatement.fetchall.php, http://php.net/manual/en/mysqli-result.fetch-assoc .php –