recursive function getting parent child
recursive function getting parent child
A recursive function is a function that calls itself during its execution. This enables the function to repeat itself several times, outputting the result and the end of each iteration.
function categoryChild($id) { $s = "SELECT ID FROM PLD_CATEGORY WHERE PARENT_ID = $id"; $r = mysql_query($s); $children = array(); if(mysql_num_rows($r) > 0) { # It has children, let's get them. while($row = mysql_fetch_array($r)) { # Add the child to the list of children, and get its subchildren $children[$row['ID']] = categoryChild($row['ID']); } } return $children; }
Recent Comments