Re: Nested database loops and completing an unordered list....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mar 1, 2012, at 7:45 PM, Jim Lucas wrote:

> On 03/01/2012 04:39 PM, Jay Blanchard wrote:
>> 
>> On Mar 1, 2012, at 6:36 PM, Jay Blanchard wrote:
>> 
>>> [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('&nbsp;',$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!
>> 
>> Forgot to say that if I isolate any one level without recursion I get all of the results for that level.
>> 
>> 
> 
> How are you calling this?  What are your initial arguments?
> 
> What does your DB schema look like?
> 
> Can you show a brief example of the data in the table?
>  Dump: SELECT * FROM position_setup WHERE company_id='3'
> 
> Can you show the output of the function above?

I initialize it by calling the function like this:

display_children(0, 0)

Each of the tiers is located in adjacent columns in a single table

tier1data, tier2data, tier 3 data……bustier1data, bustier2data…..

The array retrieves only the relevant tiers for this company and that is the output of that array at the top of my example.
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux