Hierarchy Math /:

How do I use a variable that is in a while loop? And also later in the code?
See, I’m making a page that spits out a tree (hierarchy), in the format of a table, based on the product number that goes through multiple SQL queries. In order for the hierarchy to work it needs to unravel with a series of while loops. However, what I need to do is take information from lower levels in the tree, and use it to calculate values for higher levels of the tree.

For example.
Car … =sum(door, roof, wheels) < So this would be 180

Door … =sum(window, handle) < So this would be 30

Window… 10
Handle…20
Roof…50
Wheels…100

Is there any way at all to do this? I think I now how to get the sum of the values:
[php]
while ($query_row = odbc_fetch_array($qr)) { //$qr contains the odbc_exec function. not important
$row = array();
$row_push = array_push($row, $query_row[‘price’]);
$row = array_sum($row);
}
[/php]

But this happens later in the code, and I need to echo $row before that. I know it doesn’t make any sense, but any help would be greatly appreciated. Here’s a summary of what it looks like:

[php]
while () {

echo $row; // This is where the info needs to be displayed.

while() {

$row = array_sum(); // and this is where that info comes from.

}

}
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service