This example shows how to dynamically assemble the elements and sub-elements of a menu application retrieving the values from the database.
Creating a menu
1. Create a new application “Menu“.
2. Access the “event” folder and click on “onLoad“.
3. Use the following code:
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 option.
4. Just run the application
The macro group in the “sc_appmenu” menu will perform the dynamic creation of the items. To learn more about these macros and other menu macros, access the full documentation .
Comment this post