A recursive function is one that calls itself (I'll come back to you with that solution) but it would generate just as many queries as my original suggestion.
If we use an array we can do it in two queries.
(I used my own existing table so substitute parent = father and description = category)
<?
$cnx = mysql_connect("localhost") or die("Not connected");
mysql_select_db("test",$cnx);
/* select those with no parent so we have all categories first
and place in an array */
$sql = "select id,description from tablea where parent is null";
$res = mysql_query($sql);
while (list($id, $d) = mysql_fetch_row($res)) {
$options[$id][0] = "<option value=\"$id\">$d</option>";
}
/* now get subcats and append them to the cats already in our array */
$sql = "select parent,description,id from tablea where parent is not null";
$res = mysql_query($sql);
while (list($pa, $d, $id) = mysql_fetch_row($res)) {
$options[$pa][] = "<option value=\"$id\">___$d</option>";
}
/* build options */
echo "<select name=\"category\"><br>\n";
foreach ($options as $opts) {
foreach($opts as $op) {
echo $op;
}
}
echo "</select><br>";
?>
hth