Can you try using, it shows only last occurrence $catid
, since your section outside the second loop. Now Moved into the loop section, you can view all the section with all categories.
while ($row = $result->fetch_row()){
$catgid = $row[3];
$catid = $row[0];
$cattitle = $row[1];
$catdesc = $row[2];
if($groupid == $catgid){
print('<div id="catmain">');
print('<div id="catitle">');
print('<a class="nav" href=section.php?id=' . $catid . '><img src="icon2.png" alt="folder">' . $cattitle . '</a><br /><Br/>');
print('</div>');
print('<a class="desc">' . $catdesc . '</a>');
print('</div><br />');
}
}