please look at this graph
002
003 004 005
006 007 008 009 010 011
(it's a tree)
I need to know who is the parent(002) and who is the child(003,004,005) so i use associative array to differentiate it. Here is my code
for ($j=0; $j<=count ($meta); $j++){
$query = "select * from mem_data where sp_ic = '$meta[$j]'";
//echo "<p>$query</p>";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
//echo "<p>".$row["ic_no"]."</p>";
$meta[] = $row["ic_no"];
$children[] = $row["ic_no"];
}
$children2 = $children;
for ($i =0;$i<count($children);$i++){
$child[] = array ($meta[$j]=>array ($children2 => $i));
echo "<BR>",$children2[$i];
echo $meta[$j],"<BR>";
}
}
and i try to print it through these way
reset ($child);
while (list($key,$value) = each ($child)){
echo "Parent: $key <br>\n";
while (list($key2,$value2) = each ($value)){
echo "Child : $key2<br> \n";
while (list($key3) = each ($value2)){
echo "Child2 : $key3, <br>\n";
}
}
}
echo "important";
foreach ( $child as $key => $val ){
echo $key, "<BR>";
foreach ($val as $val2 => $val3){
echo $val2,"-->",$val3;
}
}
and here is the result
Parent: 0
Child : 002
Parent: 1
Child : 002
Parent: 2
Child : 002
Parent: 3
Child : 003
Parent: 4
Child : 003
Parent: 5
Child : 004
Parent: 6
Child : 004
Parent: 7
Child : 005
Parent: 8
Child : 005
important0
002-->Array1
002-->Array2
002-->Array3
003-->Array4
003-->Array5
004-->Array6
004-->Array7
005-->Array8
005-->Array
i thought parent should return the number (002,003,004..) but instead it give out 0,1,2,3 and the parent(node) output is switch into Child, why?? and even if i try to print out the $key3 array there is nothing, does this mean it is not properly populated?
To those who know please help, any suggestion is welcome and if anyone knows where to find a detail tutorial on ASSOCIATIVE array please tell me.
Thanks for your assistance
cwyong