litebearer Posted July 14, 2010 Share Posted July 14, 2010 I have a small family tree site. The site uses 1 table (see attached image). I am able to display a person's children with no problem. /* GET CHILDREN */ $primary_children = array(); $children_query = "SELECT * from main where father_id = '$primary_id' OR mother_id = '$primary_id' ORDER BY lastname, firstname"; $children_result = mysql_query($children_query); while($children_row = mysql_fetch_array($children_result)) { $primary_children[] = $children_row['lastname'] . "~" . $children_row['firstname'] . "~" . $children_row['id']; } $i = count($primary_children); AND and able to add spouses children /* GET STEP CHILDREN */ /* LINE 100 */ if($primary_spouse_id>0) { $step_children_query = "SELECT * from main where father_id = '$primary_spouse_id' OR mother_id = '$primary_spouse_id' ORDER BY lastname, firstname"; $step_children_result = mysql_query($step_children_query); while($step_children_row = mysql_fetch_array($step_children_result)) { $primary_children[$i] = $step_children_row['lastname'] . "~" . $step_children_row['firstname'] . "~" . $step_children_row['id']; $i ++; } } when I display the array ALL the children are listed (some duplicates); (works for ALL fam members) However, when I use array_unique - some of the displayed results work perfectly while others have the 'step-chilren' removed. $num_children = count($primary_children); if($num_children>0) { $primary_children = array_unique($primary_children); } $num_children = count($primary_children); [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
litebearer Posted July 14, 2010 Author Share Posted July 14, 2010 Solved it - array_unique may leave 'gaps' in the index keys. A simple array_values 'cured' it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.