Ok. Echoing after the prices have been added, but before the function is called again, like this:
function project_addPrice($parent, $level, $price) {
$query = DB_query("SELECT id,price FROM project_data WHERE parent='$parent'");
while ($A = DB_fetchArray($query)) {
$price = $price + $A['price'];
--> echo 'ID: ' .$A['id']. ' Price: ' .$price. '<br>';
project_addPrice($A['id'], $level+1, $price);
}
//return $price;
}
This returns the correct ID's in the correct order, and looks something like this:
ID: 1 Price: 1
ID: 2 Price: 2
ID: 4 Price: 3
ID: 3 Price: 3
Remember that the order of these are:
ID:1
----ID:2
--------ID:4
----ID:3
So everything seems to be correct, and $price adds up, except for the last loop (last one should be 4). But, if I comment out the echo line, and uncomment the return $price line, all I get is 1.
I initially call the function by:
$price = project_addPrice('', 0, 0);
echo $price;