You could also get all categories first, then get all items and order them by categoryID, name. After you have all items you can create an 2d array grouped by category id.
(P.S. Again without ANY testing and error checking)
<?php
// Mysql connect shizzl here
// Get all items per categorie
$itemResult = mysql_query("SELECT * FROM Item ORDER BY catId, name") or die("Bad item query");
$itemPerCat = array();
while($row = mysql_fetch_array($itemResult)) {
$itemPerCat[$row["catId"]][] = $row;
}
// Get the categories an print the lists
$catResult = mysql_query("SELECT * FROM Cat ORDER BY name DESC") or die("Bad cat query");
while($row = mysql_fetch_array($catResult )) {
echo "<h1>".$row["name"]."</h1>\n";
if(isset($itemPerCat[$row["id"]])) {
foreach($itemPerCat[$row["id"]] as $item) {
echo $item["name"]."<br />\n";
}
}
}
?>
This method has the advantage that you are more flexible when it comes to sorting of categories, etc. However there is also a lot of overhead (2 queries, more loops).