hi, first of all: pleae use the [php] [/php] tags when posting code, it makes it easier to read.
then I'd clean it up a little even before starting to debug: you only need one query instead of that nested while loops I think.
the query should be something like
SELECT * FROM $dbtable WHERE ORDER BY Type, City DESC
then you only need to keep track of the previous type, and display it only when it changes. simplified example:
$prev_type = '';
while ($row = mysql_fetch_assoc($qry)) {
extract($row);
if ($Type != $prev_type) {
echo "<h2>$Type</h2>\n";
$prev_type = $Type;
}
// echo rest of data
}
unset($prev_type);