$arrQuestionContent = array();
$arrAnswerFile = array();
while ($qandaqrystmt->fetch()) {
$arrQuestionId[] = $qandaQuestionId;
$arrQuestionContent[] = $qandaQuestionContent;
}
...
while ($imgqrystmt->fetch()) {
$arrAnswer[] = $AnswerFile;
}
Above I have two arrays which fetchs data from db, arrQuestionContent[] fetched all questions while $arrAnswer[] fetches all answers per question.
But some questions may contain no answers which leads to an Notice: Undefined offset: for each question row in my table which does not contain an answer.
My question is that if a question row does not contain an answer, how can I get the table to display a blank row under the Answer column?
Also there is a possibility that a question has multiple answers. If that is the case then I want the question row which has multiple answers to be able to include all of its answers under the Answer column within the question row. At the moment it is only display one answer for a question row which is suppose to have multiple answers:
Below is the table:
<table id="tableqanda" align="center" cellpadding="0" cellspacing="0" border="1">
<thead>
<tr>
<th width="30%" class="question">Question</th>
<th width="12%" class="images">Answer</th>
</tr>
</thead>
<tbody>
<?php
foreach ($arrQuestionId as $key=>$question) {
echo '<tr class="tableqandarow">'.PHP_EOL;
echo '<td width="30%" class="question">'.htmlspecialchars($arrQuestionContent[$key]).'</td>' . PHP_EOL;
echo '<td width="12%" class="images">'. ( empty ($arrAnswerFile[$key]) ) ? " " : htmlspecialchars( is_array( $arrAnswerFile[$key] ) ? implode(",", $arrAnswerFile[$key]) : $arrAnswerFile[$key] ) . '</td>' . PHP_EOL;
echo '</tr>'.PHP_EOL;
}
?>
</tbody>
</table>
UPDATE:
Screenshot showing what table should look like:

UPDATE 2:
Result of var_dump($arrQuestionContent);:
array(2) { [0]=> string(19) "Name these 2 things" [1]=> string(11) "What is 4+4" }
Result of var_dump($arrAnswerFile);:
array(3) {
[0]=> string(1) "A"
[1]=> string(1) "C"
[2]=> string(1) "A"
}
Below is screenshot of table. This happens no matter if the question has an answer(s) or not:

Database:
QuestionId QuestionContent Answer
1 Name these 2 Things A
1 Name these 2 Things C
2 What is 4+4? A
Following our chat discussion we have fixed a part of the problem, which is assigning each answer to its question, for the rest, case of multiple answers, please use the following code:
and then you show the elements in your HTML table with the following:
I hope this works now, if not just tell me what it gives