When Ecshop two times in the development of Product Classification index, the classification ID to obtain the top-level classification ID. The first response is recursive, so the recursive function is written as follows:
function Getcattopid ($cat _id) { if ($cat _id) { $res = Array (); $sql = ' SELECT cat_id, parent_id ' . ' From '. $GLOBALS [' ECS ']->table (' category ') . ' WHERE cat_id = '. $cat _id. ' and is_show = 1 '; $res = $GLOBALS [' db ']->getall ($sql); if ($res [0][' parent_id '] > 0) { getcattopid ($res [0][' parent_id ']); } else { return $res [0][' cat_id ']; } } else { return 1; }}
A test program that does not get the return value? The examination for a long time did not find errors, it seems the skull is broken. Today asked the God of the gods (a good friend), he helped me to solve it, modified as follows:
function Getcattopid ($cat _id) { if ($cat _id) { $res = Array (); $sql = ' SELECT cat_id, parent_id ' . ' From '. $GLOBALS [' ECS ']->table (' category ') . ' WHERE cat_id = '. $cat _id. ' and is_show = 1 '; $res = $GLOBALS [' db ']->getall ($sql); if ($res [0][' parent_id '] > 0) { return getcattopid ($res [0][' parent_id ']);//modify place, write a return, let the function return value }< C11/>else { return $res [0][' cat_id ']; } } else { return 1; }}
The function is written internally, and even if it returns, it just returns to the inside of the function, so there is a layer of main function outside, must return again