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.

Displaying Categories for an Entry

February 28, 2011 12:24pm

Subscribe [2]
  • #1 / Feb 28, 2011 12:24pm

    Cartegraph

    83 posts

    How do you do this?

    I’ve tried the following

    {exp:query sql="SELECT cat_id FROM exp_category_posts WHERE entry_id = '{entry_id}' "}
       {exp:query sql="SELECT cat_name FROM exp_categories WHERE cat_id='{cat_id}' "}
          {cat_name}
       {/exp:query}
    {/exp:query}

    It returns the correct {cat_id} (which there are four entries) values but when {cat_id} is used to fetch the cat_name it just returns the first {cat_name} four times.

    Any Ideas?

  • #2 / Feb 28, 2011 6:35pm

    smartpill

    456 posts

    Instead of all that, have you tried:

    {categories}
    {category_name}
    {/categories}

    If that doesn’t work, post the whole template if you can. I’m not sure a query within a query will work the way you want it to which is probably why your getting repeated data.

  • #3 / Feb 28, 2011 9:11pm

    Cartegraph

    83 posts

    wow was I way over thinking it. Thanks for the reply it worked beautifully. good to know for future reference that nested query’s don’t work though.

    Thanks again, much appreciated.

  • #4 / Feb 28, 2011 9:41pm

    smartpill

    456 posts

    No problem, we’ve all been there. Glad I could help.  😉

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

ExpressionEngine News!

#eecms, #events, #releases