You could make $category_array2 global

function getGrandParent($cat_id, $year_model_id, $x)
{
    global $category_array2
...

olinux


--- Thomas Moore <[EMAIL PROTECTED]> wrote:
> I am trying to return a variable from a recursive
> function. If the recursive
> function gets called, the nothing is returned. For
> example, below I am
> trying to get the category_array2 variable returned.
> It works if the
> recursive function within the IF statement does not
> get called, but if it
> does, it does not pass back the variable.
> 
> Any help would be greatly appreciated. I am tearing
> hair at this point!
> -tom
> 
> showMasterCategories($year, $model_id,
> $syear_model_id, $keyword, $make_id,
> $display_mode, $catid)
> {
>       $category_array2[$i] = getParent($category_id,
> $year_model_id, $i, $catid);
> }
> 
> 
> function getGrandParent($cat_id, $year_model_id, $x)
> {
>  // to get highest level category "master category"
>  $query = "SELECT distinct C2.category_id,
> C2.category, CC2.category_id ";
>  $query .= " FROM CATEGORY C2, CHILD_CATEGORY CC,
> CHILD_CATEGORY CC2";
>  $query .= " where C2.category_id = CC.category_id
> and CC.child_category_id
> = $cat_id and  CC2.child_category_id =
> C2.category_id";
> 
>  //print "$query";
>  $result99 = mysql_query($query)
>      or die("Query failed - $query");
> 
>  list( $ch_category_id, $category, $pcategory_id) =
> mysql_fetch_row($result99);
> 
>  if ($pcategory_id == 0) {
> 
>   print "PARENT=>
> $category:$pcategory_id:$year_model_id: $x<br>";
>   $category_array2[$x] =
> "$category:$ch_category_id:$year_model_id";
>   print "just before returning:
> $category_array2[$x]";
>   return $category_array2[$x];
>   $x = $x + 1;
>  } else {
>   print "<br>cat-> $category
> id->$ch_category_id<br>";
>   getGrandParent($ch_category_id, $year_model_id,
> $x);
>  }
>  //print "$query";
>  //$result_set = mysql_num_rows($result);
> }
> 
> 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to