The idea of asking a logical arithmetic algorithm
The meaning is that a is the parent of B, B is the parent of C, and so on, infinitely deferred classification;
Each of these members has a corresponding value, which is a random number with a value of 1-30;
Now it's time to calculate that when I randomly select a member, I can calculate the sum of the value values accumulated by this member and all of the parent members up to which member the total value exceeds 200.
------Solution--------------------
Recursion.
Recursive functions within a class
function test ($id, $num =0, $max =200) {
$sql = "Select * from {{test}}" WHERE id= $id ";
$res =yii::app ()->db->createcommand ($sql)->queryrow ();
$num + = $res [' value '];
if ($num < $max) {
$name =self::test ($res [' pid '], $num);
}else{
$name = $res [' name '];
}
return $name;
}
Call
$tr =new classtest ();
Echo $tr->test (7);
Result D