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.

Syntax error in exp:query

July 11, 2007 10:17am

Subscribe [4]
  • #1 / Jul 11, 2007 10:17am

    Maurice

    9 posts

    Hi,

    I get an error with my exp:query code:

    {exp:query sql="SELECT COUNT(cat_id) AS count FROM exp_categories WHERE parent_id = '4';"}
    {count}
    {/exp:query}

    Error:


    Error

    The following tag has a syntax error:

    {exp:query}

    Please correct the syntax in your template.

    I cannot find the problem, can someone help me?
    Thank you

  • #2 / Jul 11, 2007 10:21am

    Robin Sowell

    13255 posts

    I’d drop the ; from it- but I just did a cut/paste of the above to my site and it comes back fine.  Double check that the module is installed- in ‘Modules’ make sure that ‘Query Module’ shows as ‘Installed’.  Hopefully, that’s the issue.  If not, first thing I’d do is upload a clean copy of the query folder.

  • #3 / Jul 11, 2007 10:28am

    Ingmar

    29245 posts

    You are not, by any chance, using EE Core? Cause it does not come with the Query module.

  • #4 / Jul 11, 2007 11:08am

    Robin Sowell

    13255 posts

    Heh- yea, that would do it as well.  (And the query module wouldn’t show up as an option in the ‘Modules’ tab.)

  • #5 / Jul 11, 2007 11:20am

    Maurice

    9 posts

    The query module was not installed. It is installed now.

    maybe someone can help me with:

    If there are no subcategories in a category it should display “no subcategory”:

    {exp:query sql="SELECT COUNT(cat_id) AS count FROM exp_categories WHERE parent_id = '{category_id}';"}
    {count}
    {/exp:query}

    I tried several things like:

    {exp:query sql="SELECT COUNT(cat_id) AS count FROM exp_categories WHERE parent_id = '{category_id}';"}
    {if count < 1} No subcategories {/if}
    {/exp:query}

    But i aint get it work. It shows the {count} where there are (multiple) subcategories. But when an category has no subcategories it does not show “no subcategories”.

    Can someone help me?

    Thank you for the fast reply

  • #6 / Jul 11, 2007 11:29am

    Robin Sowell

    13255 posts

    Try the {if no_results} conditional- it works with the query module.  Should get you squared away.

  • #7 / Jul 11, 2007 11:54am

    Maurice

    9 posts

    It aint work… I already tried it…

  • #8 / Jul 11, 2007 12:06pm

    Robin Sowell

    13255 posts

    Try it with an alias- it may be a conflict with the {count} variable- depending on the version you’re running.  This worked for me:

    {exp:query sql="SELECT COUNT(cat_id) AS mcount FROM exp_categories WHERE parent_id = '444';"}
    {if mcount < 1}No subs
    {if:else}
    Mcount {mcount}
    {/if}
    {/exp:query}
  • #9 / Jul 11, 2007 1:59pm

    Maurice

    9 posts

    It still aint works…

    It looks very easy, except it is not

  • #10 / Jul 11, 2007 9:50pm

    Sue Crocker

    26054 posts

    Maurice, if you hard code the {category_id} to a real category_id, does it work?

    Try putting {category_id}
    right before your query.

  • #11 / Jul 12, 2007 9:17am

    Maurice

    9 posts

    {category_id} is turning out an ID, so this can not be the problem.

    The exact code:

    {exp:weblog:categories weblog="{embed:weblog}" parent_only="yes" style="linear" show="not 15"}
        {exp:subcategories root_node="{category_id}"}
            {exp:query limit="1" sql="SELECT COUNT(cat_id) AS mcount FROM exp_categories WHERE parent_id = '{category_id}';"}
                {category_id}
            {/exp:query}
        {/exp:subcategories}
      <li><a href="#" class="toggle">{category_name}</a>
        <ul id="show{category_id}" class="show">
          {exp:subcategories root_node="{category_id}"}
            <?php $desc = "{subcategory_description}"; ?>
            <?php if($desc != '') { ?>
            <li id="toggle{subcategory_id}">
              <a href="http://{subcategory_description}" target="_blank" rel="noopener">{subcategory_name}</a>
            </li>
            <?php } else { ?>
            <li id="toggle{subcategory_id}">
              <a href="/{embed:template}/category/C{subcategory_id}/">{subcategory_name}</a>
            </li>
            <?php } ?>
          {/exp:subcategories}
        </ul>
      </li>
    {/exp:weblog:categories}

    At the top of the code you see my query

  • #12 / Jul 12, 2007 10:06am

    Robin Sowell

    13255 posts

    Ah- well, the basic query should work if you’re on the latest version as I tested it and it does.  But nesting it- there could be variable conflicts.

    Let’s start over a bit- what’s the ultimate goal you’re going for here?  It may be easier and a lot leaner (I’d be hesitating to do the above due to the possible number of queries) to do the whole thing with a single query.  Or a plugin.  Have you checked out the cat lister plugin?  It gives you finer grain control over category navigation.  And I wrote a dynocat plugin- don’t think it will do what you want, but it might be possible to riff off of the code.

    I’m not totally up on the subcategories plugin- but if it’s using any queries, I’m thinking the above navigation could get resource intensive fast.

    Also- I’m going to shift this to ‘How to’- it’s not so much a problem with the query module but an issue for brainstorming how to achieve a creative/custom nav.

  • #13 / Jul 12, 2007 10:10am

    Sue Crocker

    26054 posts

    You need to do some reduction testing. The code that Robin supplied previously, does that work if you hard code the category_id?

    You’d test this in a brand new template with *just* that code in it.

  • #14 / Jul 12, 2007 10:11am

    Derek Jones

    7561 posts

    Along with what Robin said, what version and build are you on?  It’s important to be on the latest, to make sure there are no bugs that are in play.

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

ExpressionEngine News!

#eecms, #events, #releases