Hi Justin,
my proposed solution in PHP code and SQL.
<?php
//The Parent value
$parent_value;
// Check if parent value in Parent Column >5 times
$sql_parent = "SELECT COUNT() FROM mySQLTable WHERE parent = $parent_value";
$db=mysql_connect();
$result = mysql_query($sql_parent,$db);
$row = mysql_fetch_row($result);
if($row[0] > 5) {
$sql_child = "SELECT child FROM mySQLTable WHERE parent = $parent_value";
$result = mysql_query($sql_child,$db);
while($rowC = mysql_fetch_row($result)) {
$child_value = $rowC[0];
$parent_check_sql = "SELECT COUNT() FROM mySQLTable WHERE parent = $child_value";
$resultD = mysql_query($parent_check_sql, $db);
$rowD = mysql_fetch_row($result);
if($rowD[0] < 5) break;
}
$desired_result = $child_value;
}
mysql_disconnect();
?>
Is that what you wanted? 🙂 My solution is different from your logic but you should get the same desired value.
Terry
PS I dun think the code is complete. but the general idea is there.