I'm trying to write a function that will define and pass TWO global variables. Some some reason, it's not working. Let me start w/ the function itself. Here it is:
function categoryOptionTags($id,$top_level_id,$match_on_cat_id) {
global $connection;
if($top_level_id != "NULL") global $top_level_id, $match_on_cat_id;
print "top_level_id: ".$top_level_id."<br />\n";
print "match_on_cat_id: ".$match_on_cat_id."<br />\n";
static $tab;
$tree_query = "SELECT cat_id, cat_title FROM categories WHERE cat_parent_id=".$id." ORDER BY cat_rank ASC";
$tree_result = @mysql_query($tree_query) OR die ("Couldn't complete this MySQL query: ".$tree_query."<br />\n<br />\nError: ".mysql_error());
if(mysql_num_rows($tree_result) > 0) {
$oldtab = $tab; // backup tab
if($id != $top_level_id) $tab .= ' - '; // increase tab
while($row = mysql_fetch_array($tree_result)) {
print "\t\t<option value=\"".$row["cat_id"]."\"";
if($row["cat_id"] == $match_on_cat_id) print " selected=\"selected\"";
print ">".$tab."".$row["cat_title"]."</option>\n";
categoryOptionTags($row["cat_id"],NULL,NULL);
}
$tab = $oldtab; // restore tab
}
}
So I'm using a recursive function here to create a list of drop_down options for the categories. It works fine to create all the option tags, and the "tab" works to show the appropriate "levels".
However, if I pass an ID number of particular category that is more than one level deep, it's not hitting the "if($row["cat_id"] == $match_on_cat_id) print " selected=\"selected\"";" line. I honestly don't see why, since the definition of the top_level_id variable works as I want it to and this is more or less coded the same way.
Any ideas?