ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Joining two SQL queries

March 11, 2011 8:57pm

Subscribe [2]
  • #1 / Mar 11, 2011 8:57pm

    Skyyr

    1 posts

    Hello…

    I’m developing a category-based navigation system (it’s done for the most part). I’m needing a conditional that will check to see if a main category has subcategories. If it doesn’t, then it will display a message to the user.

    I developed a script that works fine theoretically, but for whatever reason, I can’t use {no_results} because its overridden by the categories tag (instead of working correctly in regards to the exp:query tag).

    I’m not familiar at all with SQL JOIN statements, nor am I sure that’s even the route that I should go, but I’ve seen people accomplish similar using them. Is there a way to join the functionality achieved using the two EE tags below and create a single query that accomplishes what I need it to?


    {exp:channel:categories channel="resources" style="linear"}
      {if category_url_title == segment_2}
          {exp:query sql="SELECT cat_id FROM exp_categories WHERE parent_id = '{category_id}’ LIMIT 1”}
            {if no_results}
              No subcategories exist for this section.
            {/if}
          {/exp:query}
      {/if}
    {/exp:channel:categories}


    Thanks!

  • #2 / Aug 01, 2011 5:15pm

    the3mus1can

    426 posts

    Unless I am mistaken the {exp:channel:categories} tag does not have a no_results conditional.  If that is correct, then it could be two things.

    Is there a {exp:channel:entries} tag around the code you posted here?

    Or try adding parse=“inward” to the {exp:channel:categories} as the {category_id} might not be getting parsed properly.  If you turn on template debugging you should be able to see if the {category_id} in the sql statement is getting parsed properly.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases