There are 4 sitiations of which I resolves 3 but not the 4th
SS (Branch ending with 2 descendents => stop routine)
KS/SK (Branch with one descendent and one further branch => keep looping)
KK (Two branches => keep looping but it get complex looping to remember both branches)
Code:
while (($run<>0) // if run=0 stop looping
{
unset ($key);
$Qtxn = 'SELECT taxon,thiskey,child,typ FROM ' . $table . ' WHERE thiskey='.$k.'';
$Rtxn = mysql_query($Qtxn) or die ('Error in query: ' . $Qtxn . mysql_error());
while ($row = mysql_fetch_array($Rtxn)) {$key[] = $row; }
print "Now working on key $k - - - switch: $run ";
// Access tree ($table) walk through its branches and get data for each branch into an array ($key[])
"<br>";
// $taxa = array to place extracted descendents
//kk situation where it makes things complex
if ($key[0]['typ']=='k' AND $key[1]['typ']=='k')
{
print "<b>[KK]</b> : ";
$k = $key[0]['child']; print "nextkey = $k " ;
$k2 = $key[1]['child']; print "and = $k2 <br>" ;
$run = 1; $run2 = 1;
}//if
//ks situation, works fine
if ($key[0]['typ']=='k' AND $key[1]['typ']=='s')
{
print "<b>[KS]</b> : ";
array_push($taxa, $key[1]['taxon']);
$k = $key[0]['child']; print "nextkey = $k <br>" ;
$k2 ='';
$run = 1;
} //if
//sk situation, works fine
if ($key[0]['typ']=='s' AND $key[1]['typ']=='k')
{
print "<b>[SK]</b> : ";
array_push($taxa, $key[0]['taxon']);
$k = $key[1]['child']; print "nextkey = $k <br>";
$k2 ='';
$run = 1;
}//if
//ss situation, works fine, both branches are descendents, stop looping ($run set to 0)
if ($key[0]['typ']=='s' AND $key[1]['typ']=='s')
{
print "<b>[SS]</b> : ";
array_push($taxa, $key[0]['taxon'], $key[1]['taxon']);
$run = 0; print "End <br>";
$k2 ='';
} //if