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
https://forums.phpfreaks.com/topic/207747-another-array_unique-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.