I did it with a table recursive. I hope can help you.
You must change the SQL and fields name
First All you must create a TREE MENU with SC
(for example: treemenu_agr)
THEN CREATE A PHP METHOD: GetChilds with parameters:
menu by reference
sql by value
codefather by value
This is code for GetChilds :
sc_lookup(rs_child, $sql.$codefather. " order by agr_nmbre");
foreach({rs_child} as $agr_child)
{
$agr_cdgo = $agr_child[0];
$agr_cdgop = $agr_child[1];
$agr_nmbre = $agr_cdgo."-".$agr_child[2];
sc_appmenu_add_item($menu,"$agr_cdgo","$codefather",$agr_nmbre,form_agr_tree,neg_cdgo=[neg_cdgo];agr_cdgo=$agr_cdgo,);
getChilds($menu, $sql, $agr_cdgo );
}
ONLOAD EVENT
// Get params from a app.
if(isset($_POST[‘nmgp_parms’]) && substr($_POST[‘nmgp_parms’], 0, 10)==“v_agr_cdgo” && isset([v_agr_cdgo]) && !empty([v_agr_cdgo]))
{
$agr_cdgo_parm = [v_agr_cdgo];
}
$menu = “treemenu_agr”;
//-------------------------------------------------------------------------
sc_appmenu_reset($menu);
sc_appmenu_create($menu);
//-------------------------------------------------------------------------
$sql_root = “select agr_cdgo, agr_cdgop, agr_nmbre from agr_agrpcion where neg_cdgo = “.[neg_cdgo].” and agr_cdgop is null order by agr_nmbre”;
$sql_child = "select agr_cdgo, agr_cdgop, agr_nmbre from agr_agrpcion where agr_cdgop = ";
sc_lookup(rs_root, $sql_root);
$items = false;
foreach({rs_root} as $agr_root)
{
$items = true;
$agr_cdgo = $agr_root[0];
$agr_cdgop = $agr_root[1];
$agr_nmbre = $agr_cdgo."-".$agr_root[2];
//sc_appmenu_add_item(“String Menu_Name”, “Id_Item”, “Id_Parent”, “Label”, “Aplication”, “Parameters”, “Icon”, “Hint”, “Target”)
sc_appmenu_add_item($menu,"$agr_cdgo",$agr_nmbre,form_agr_tree,neg_cdgo=[neg_cdgo];agr_cdgo=$agr_cdgo);
getChilds($menu, $sql_child, $agr_cdgo);
}
if(!$items) {
sc_redir(form_agr, neg_cdgo=[neg_cdgo];agr_cdgo=0, “$menu”);
}