Jump to content

Another array_unique problem


litebearer

Recommended Posts

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.