function selectUnits($previous_unit, $indent, $members_unit)
{
    global $db;
    $indent++;
    //$formatting = str_repeat("     ", $indent);
    $formatting = str_repeat('<img src="images/tree_leaf.gif" />', $indent);
    $result = $db->Query("SELECT `unit_id`, `name` FROM `rudi_combat_units` WHERE `detachment` = '{$previous_unit}'");
    $row = $db->Fetch($result);
    foreach ($row as $unit) {
        $unit_id = $unit['unit_id'];
        $unit_name = $unit['name'];
        echo $formatting . '<img src="images/tree_branch.gif" />&nbsp;' . $unit_name . '<br />';
        selectUnits($unit_id, $indent, $members_unit);
    }
}
function selectUnits($previous_unit, $indent, $members_unit)
{
    global $db;
    $indent++;
    $formatting = str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $indent);
    $result = $db->Query("SELECT `unit_id`, `name` FROM `rudi_combat_units` WHERE `detachment` = '{$previous_unit}'");
    $row = $db->Fetch($result);
    foreach ($row as $unit) {
        $unit_id = $unit['unit_id'];
        $unit_name = $unit['name'];
        if ($members_unit == $unit_id) {
            echo '<option value="' . $unit_id . '" selected>' . $formatting . $unit_name . '</option>';
        } else {
            echo '<option value="' . $unit_id . '">' . $formatting . $unit_name . '</option>';
        }
        selectUnits($unit_id, $indent, $members_unit);
    }
}
			<td class="right" style="font-weight:bold;">Unit:</td>
			<td class="left">
			<select name="unit">
		    	<option value="0">N/A</option>
<?php 
$result = $db->Query("SELECT `unit_id`, `name` FROM `rudi_combat_units` WHERE `detachment` = 0 ");
$row = $db->Fetch($result);
foreach ($row as $unit) {
    $unit_name = $unit['name'];
    $unit_id = $unit['unit_id'];
    if ($member['cunit_id'] == $unit_id) {
        echo '<option value="' . $unit_id . '" selected>' . $unit_name . '</option>';
    } else {
        echo '<option value="' . $unit_id . '">' . $unit_name . '</option>';
    }
    selectUnits($unit_id, 0, $member['cunit_id']);
}
?>
		    	</select>
			</td>
		</tr>
		<tr><td class="right">Primary Weapon:</td><td class="left">
			<select name="weapon">
<?php 
$weapons = GetWeapons();
foreach ($weapons as $weapon) {
    echo "<option value=\"{$weapon['weapon_id']}\">{$weapon['model']}</option>";
}
?>
		</select>
		</td></tr>