I made a form to show the correct answers for homework after the homework is finished.
The student enters his or her course code, like 19BE and the week he or she wants to see, like Week1.
There is a table, 19BEcorrectAnswers.
The table has the columns:
id, questionnr, Week1, Week2, Week3 … Week18
The thing is, each week may have a different number of of entries in each WeekX column.
For example, Week1 has 17 entries, Week2 has 28 entries.
In the column Week1, after row 17 there is nothing, NULL entry.
The rows in the column ‘questionnr’ look like this: Question1, Question2, Question3 … Question28
The table is at present 28 rows deep, but that may change to more, so it can hold more answers.
First, if the form entries are correct, I get:
$result = $pdo->query($sql);
then:
if(isset($_POST['weeknr'])) {
foreach ($result as $row)
{
$numname[] = array(
'questionnr' => $row['questionnr'], 'weeknr' => $row[$weeknr],);
}
include 'output.html.php';
exit();
}
This does what I want. I get a nice 2 column table with the questionnr and the answer in each row.
It is not a big problem, but, if I query Week1, I still get 28 rows of output.
Can you think of an easy way to suppress the output if the entry in say, column Week1 is NULL, so that Week1 only shows 17 rows??
Thanks for any tips or advice!