Using Server Side Code to use the DynAPI

Because the DynAPI is a set of javascript-based functions it works on the client side, that is, when the browser parses the javascript code. So in order to use server-side code to control the menus programmatically we need to generate function calls to the DynAPI using server-side code.

Also notice that the menus will display scroll buttons if the menu is too large for the browser's window.
This is because we enabled the "Global In-Group Scrolling" option under File->Project Properties->Global Settings->Extended Features

The sample below uses PHP and MySQL to add commands to an empty group from information on a database.

<script language="JavaScript">
    var nc;

    // First of all we need to initialize the DynAPI
    dmbAPI_Init();

    <?
        // Connect to the MySQL server
        mysql_connect("localhost","db_user","db_password");
        mysql_select_db("dmbwebs");

        // Get 10 random entries from the database
        $q = mysql_query("select * from webs order by rand() limit 10;");
        $t = mysql_num_rows($q);

        $i = 0;
        while($i < $t) {
                // Get the name and URL of the web site
                $wname = mysql_result($q, $i, "Name");
                $url = mysql_result($q, $i, "URL");

                // Generate the code to create a command
                echo "nc=dmbAPI_addCommand('Group001', '".addslashes($wname)."', ".($i<$t-1?"true":"false").");\n";

               // Generate the code to set the new command's URL
                echo "dmbAPI_setOnClick(nc, '$url', '_blank', 'false');\n";

                $i++;
        }

        // Close the connection to the MySQL server
        mysql_close();
    ?>
</script>

Click the Refresh button to refresh the page and rebuild the menu with 10 different entries from the database