Get a list of categories, and then subcategories in each categories.
<?php
$categories = array();
foreach ($results as $result) {
$category = $result['category'];
$categories[$category][] = $result['subcategory'];
}
This will then give you a multidimensional array, with categories and the keys, and the sub-categories as the values. You can loop over them as thus:
<ul>
<?php foreach ($categories as $category => $subcategories): ?>
<li>
<?php echo $category; ?>
<ul>
<?php foreach ($subcategories as $subcategory): ?>
<li><?php echo $subcategory; ?></li>
<?php endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>