Re: Nested database loops and completing an unordered list....
| From: | Jay Blanchard | Date: | Fri, 02 Mar 2012 00:36:49 +0000 |
| Subject: | Re: Nested database loops and completing an unordered list.... | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316827@lists.php.net to get a copy of this message | ||
[snip]…stuff…[/snip]
I am getting close, but I am also getting frustrated. I probably need to walk away for a bit.
I have an array of tiers….
Array
(
[0] => TIER1DATA
[1] => TIER2DATA
[2] => TIER3DATA
[3] => BUSTIER1DATA
[4] => BUSTIER2DATA
[5] => BUSTIER3DATA
[6] => BUSTIER4DATA
)
Each of the tiers which represent parents in children in pairs. TIER1DATA is the parent of
TIER2DATA, etc. representing 7 columns of data. Here is my code so far - any insight would be
valuable and extremely appreciated by me.
function display_children($i, $child) {
global $dbc;
global $tierArray;
echo $i."<br />";
/* retrieve children of parent */
$get = "SELECT DISTINCT
". $tierArray[$i] ." FROM
POSITION_SETUP ";
$get .= "WHERE COMPANY_ID = '3' ";
if($i > 0) {
$get .= "AND " . $tierArray[$i - 1] . " = '" . $child .
"' ";
}
echo $get."<br />";
if(!($result = mysql_query($get, $dbc))) {
echo mysql_errno() . "\t" . mysql_error() . "\n";
exit();
}
while($row = mysql_fetch_array($result)) {
/* indent and display the title of this child */
echo str_repeat(' ',$i).$row[$tierArray[$i]]."<br />\n";
/* get the children's children */
display_children($i + 1, $row[$tierArray[$i]]);
}
}
It does produce the right query for only the first child in each case, I cannot get it to go deeper.
I have just been looking at it for too long. TVMIA!