Howdy;
I’m trying to crawl up a category tree using the query sql - and I’ve run into a issue I just can’t get a grasp of
here’s the code
——code——
{exp:query sql="SELECT parent_id AS myMomIndex FROM exp_categories WHERE cat_id = {last_index}"}
<?
$iam ='{last_segment}';
$mom = '{myMomIndex}';
?>
{exp:query sql="SELECT parent_id AS myGrandMom, cat_name AS mommyName FROM exp_categories WHERE cat_id = {myMomIndex}"}
<?
$momName ='{mommyName}';
$grandmom = '{myGrandMom}';
?>
{exp:query sql="SELECT cat_name AS greatGrandMomName, parent_id AS greatGrandMom FROM exp_categories WHERE cat_id = {myGrandMom}"}
<?
$grandmomName = '{greatGrandMomName}';
?>
{/exp:query}
{/exp:query}
{/exp:query}——code——
now as convoluted as that may looks, it works, all those variables get set or remain/return 0 if a given category doesn’t have two levels of hierarchy - but here’s the weird thing - if I go up to a category that is at a top level (no mom / no grandmom is this concept) the third query doesn’t just fail - it actually drops its ‘{/exp:query}’ closing tag on the page.. I’ve tried all manners of wrapping the second and third queries in a conditional (both EE and PHP conditionals) and it still seems to fire off…
any help would be greatly appreciated—I’m baffled..