Don't know if this helps, but a while ago, I read about creating a 'nested' repeat with a single recordset. - and I use this technique quite a bit.
Unfortunately I can't find the link to the article, so I dug up an old example and updated it to work with mysqli
The technique is to order the recordset by the 'parent' and then use a php if block to display the parent if it is different to the previous row, otherwise put a non breaking space.
It works fine in a table, you may be able to use the same logic
eg
<?php $previous = "";?>
<table>
<tr>
<th>Parent</th>
<th>Child</th>
</tr>
<?php
while(!$Recordset1->atEnd()) {
?>
<tr>
<td>
<?php
// display field if it doesn't match previous value
if ($Recordset1->getColumnVal("Parent") != $previous) {
echo $Recordset1->getColumnVal("Parent"); ?>
<?php
} else {
// otherwise, insert a non-breaking space
echo ' ';
}
// set $previous to current value for next time
$previous = $Recordset1->getColumnVal("Parent");
?>
<td>
<td><?php echo($Recordset1->getColumnVal("Child")); ?>
<td>
<?php
$Recordset1->moveNext();
}
$Recordset1->moveFirst(); //return RS to first record
?>
</tr>
</table>