a

Dynamic menu

This example shows how to dynamically assemble the items and sub-items of a menu application by getting values from the database.

   

Creating a Menu

1. Create a new application "Menu".

   

2. Access the events folder and click on "onLoad".

   

3. Use the code below:

onLoad

sc_appmenu_reset(mcr14);
sc_appmenu_create(mcr14);

sc_lookup(dscategories,"SELECT categoryid,CategoryName FROM categories");

foreach({dscategories} as $arr_category){

sc_appmenu_add_item(mcr14,'item_'.$arr_category[0],, $arr_category[1],mcr14_2,catid=$arr_category[0];catname=$arr_category[1], , , );

$sSQL = "SELECT productid,productname FROM products
WHERE categoryid = '".$arr_category[0]."'";

sc_lookup(dsproducts,$sSQL);

if(!empty({dsproducts}))
foreach({dsproducts} as $arr_product){

sc_appmenu_add_item('mcr14','item_'.$arr_category[0].$arr_product[0],'item_'.$arr_category[0], $arr_product[1],mcr14_1,prodid=$arr_product[0], , , );
}
}

Note: mcr14_2 and mcr14_1 are applications that will be opened by the menu item.

 

4. Click the Run button on the toolbar.

   

Click on the button below to view the application.