I didn't think this would give me any trouble, but it is. I just want to run a query depending on the URL segments.

I have this now:

        {if segment_3 != ''}
            {exp:query sql="SELECT a.cat_id, a.parent_id, b.cat_name FROM exp_categories a, exp_categories b WHERE a.cat_url_title = '{segment_3}' AND b.cat_url_title = '{segment_2}'"}
        {if:else}
            {exp:query sql="SELECT cat_id, parent_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
        {/if}
            ...
        {/exp:query}

But every time I wrap it in the IF statement, I get nothing...

up vote 5 down vote accepted

This happens because of the "else". If you use else, the conditional became advanced and it will be parsed after the modules.

Try this:

{if segment_3 != ''}
   {exp:query sql="SELECT a.cat_id, a.parent_id, b.cat_name FROM exp_categories a, exp_categories b WHERE a.cat_url_title = '{segment_3}' AND b.cat_url_title = '{segment_2}'"}
{/if}
{if segment_3 ==''}
    {exp:query sql="SELECT cat_id, parent_id FROM exp_categories WHERE cat_url_title = '{segment_2}'"}
{/if}
        ...
{/exp:query}

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.