NOTE: There's a new version of this sample that uses the new dmbAPI_parseArray function.

In this sample you can see how recursive functions are used to create a multilevel menu.
(Updated 27/Jun/2007)

The structure of the public forum used in xFX JumpStart is generated from information stored in a table using a series of IDs and ParentIDs chain. Forums with an ParentID of -1 indicate top level forums and those with a ParentID other than -1 indicate a sub forum.
This ID<->ParentID relationship is enough for us to build a simple PHP script that scans all the available forums and generates the necessary DynAPI to build a menu that represents the forums' structure.

<script language="javascript">
var i;
var si;

dmbAPI_Init();

<?
    mysql_connect("localhost","root","abc12345");
    mysql_select_db("ipb");

    $c = mysql_query("select * from ipbf_xfx_forums where parent_id=-1 order by position;");
    $tc = mysql_num_rows($c);
    $ci = 0;
    while($ci < $tc) {
        $cid = mysql_result($c, $ci, "id");
        $gn = "grp".$cid;
        echo "i = dmbAPI_addTBItem(1, '".mysql_result($c, $ci, "name")."');\n";
        echo " dmbAPI_addGroup('".$gn."');\n";
        echo " dmbAPI_setOnMouseOver(i, '".$gn."', '', true, 0);\n";

        addForums($cid, $gn);

        $ci++;
    }

    mysql_close();

    function addSubCategories($cid, $gn) {
        $sc = mysql_query("select * from ipbf_xfx_forums where parent_id=$cid order by position;");
        if($sc) {
            $tsc = mysql_num_rows($sc);
            $sci = 0;
            while($sci < $tsc) {
                $scid = mysql_result($sc, $sci, "id");
                $sgn = "grp".$scid;

                echo " si = dmbAPI_addCommand('".$gn."', '".mysql_result($sc, $sci, "name")."');\n";
                if(hasSubItems($scid)) {
                    echo " si = dmbAPI_setImageRightNormal(si, '/menu/images/arrow_bloack.gif', 12, 11);\n";
                    echo " si = dmbAPI_setImageRightOver(si, '/menu/images/arrow_bloack.gif', 12, 11);\n";

                    echo " dmbAPI_addGroup('".$sgn."');\n";
                    echo " dmbAPI_setOnMouseOver(si, '".$sgn."', '', true, 6);\n";

                    addForums($scid, $sgn);
                } else
                    echo " si = dmbAPI_setOnClick(si, '/uboards/forums/index.htm?showforum=".$scid."', '_blank');\n";

                $sci++;
            }
        }
    }

    function hasSubItems($cid) {
        $sc = mysql_query("select id from ipbf_xfx_forums where parent_id=$cid;");
        if($sc) return (mysql_num_rows($sc)>0);
        return false;
    }

?>
</script>