I am trying to build a simple "cookie trail" of categories where it will print a string like this when I pass it a given number:
Level 1 > Level 2 > Level 3
And here is a copy of the function that I wrote:
function createSimpleCookieTrail($category_id, $cookieTrail) {
$category_search_query = "SELECT category_parent_id, category_title FROM categories WHERE category_id='".$category_id."'";
//echo "<p><strong>category_search_query</strong>: ".$category_search_query."</p>\n";
$category_search_result = @mysql_query($category_search_query) OR die ("Couldn't complete this MySQL query: ".$category_search_query."<br />\n<br />\nError: ".mysql_error());
$category = mysql_fetch_array($category_search_result);
if(mysql_num_rows($category_search_result) > 0) {
echo "\$cookieTrail: ".$cookieTrail."<br />\n";
if($cookieTrail != "") {
$cookieTrail = " > ".$cookieTrail;
}
$cookieTrail = htmlentities($category["category_title"]).$cookieTrail;
createSimpleCookieTrail($category["category_parent_id"], $cookieTrail);
echo "\$cookieTrail: ".$cookieTrail."<br />\n";
}
echo "FINAL Cookie Trail: ".$cookieTrail."<br />\n";
return $cookieTrail;
}
When I run that function on the site w/ some live data and view the values that are printing, it seems to get the right value to first time from the function, but then continues to run the function for some reason and then REDUCE the cookie trail. For example, when I ran this function on the server, it echoes this data to the browser:
$cookieTrail:
$cookieTrail: Indoor
$cookieTrail: SA Series > Indoor
$cookieTrail: 2.4 GHz > SA Series > Indoor
$cookieTrail: Amplifiers > 2.4 GHz > SA Series > Indoor
FINAL Cookie Trail: Products > Amplifiers > 2.4 GHz > SA Series > Indoor
$cookieTrail: Products > Amplifiers > 2.4 GHz > SA Series > Indoor
FINAL Cookie Trail: Products > Amplifiers > 2.4 GHz > SA Series > Indoor
$cookieTrail: Amplifiers > 2.4 GHz > SA Series > Indoor
FINAL Cookie Trail: Amplifiers > 2.4 GHz > SA Series > Indoor
$cookieTrail: 2.4 GHz > SA Series > Indoor
FINAL Cookie Trail: 2.4 GHz > SA Series > Indoor
$cookieTrail: SA Series > Indoor
FINAL Cookie Trail: SA Series > Indoor
$cookieTrail: Indoor
FINAL Cookie Trail: Indoor
Indoor
So the return of the function is giving me back simply Indoor instead of Products > Amplifiers > 2.4 GHz > SA Series > Indoor. I've been looking at this for a while now and I can't for the life of me figure out why it is seemingly re-submitting the function and dwindling back down after it builds it up.
Any ideas?
Thanks,
Shaun