I made this off the top of my head, so it may take a little debugging for you to get it. I'll use MySQL as the database server. It also assumes you already started your HTML select tag and that your parent_id is zero if it is a top level category
function show_categories($parent_id="0",$insert_text="") {
$categories=mysql_query("SELECT * FROM categories WHERE parent_id=".$parent_id." ORDER BY cat_name");
while ($category=mysql_fetch_array($categories)) {
echo("<option name='".$category["cat_id"]."'>".$insert_text.$category["cat_name"]."</option>");
show_categories($category["cat_id"],$insert_text."--");
}
return true;
}
show_categories();
It will take some debugging probably, since I haven't copied this from something I've tried