I don't understand why you need this field at all. The impression I have of the table is if a record exists, that it is assumed that attendance would exist.
Does a record exist for every date and applied either an A or P in the attendance field for every student? It's a bit of a waste in dataspace IMO to do that, but you can modify it easily as well by changing the array creation in the while:
PHP Code:
if (!isset($aRecords[$id]))
{
$aRecords[$id] = array(
'id' => $id,
'studname' => $studname,
'studroll' => $studroll,
'attendance' => array($date => $attendance), // I don't know what this is, so I'm leaving it out
);
else
{
$aRecords[$id]['attendance'][$date] = $attendance;
}
To that, and modifying the foreach at the end to this:
PHP Code:
foreach ($aRecords AS $record)
{
$att = array_pop($record);
print('<tr>');
vprintf('<td>%s</td><td>%s</td><td>%s</td>', $record);
printf('<td>%s</td>', implode('</td><td>', $att);
print('</tr>');
}
Looks like it would do it.