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.

Is it possible to assign exp:query result to a variable?

October 25, 2010 5:23pm

Subscribe [2]
  • #1 / Oct 25, 2010 5:23pm

    Rudy Affandi

    9 posts

    Hi all,

    Is it possible to assign the result of a query to a preload_replace variable? See my query code below:

    {exp:query sql="SELECT cat_id FROM exp_categories WHERE parent_id = '{segment_3_category_id}' "}
    {cat_id}
    {/exp:query}

    Also, is there a way to set a custom delimiter to the exp:query output? In this case, I am trying to generate a pipe-delimited output.

    Thanks, as always, any help would be greatly appreciated.

    Rudy

    Moved to CodeShare Corner by Moderator

  • #2 / Oct 27, 2010 1:17am

    the3mus1can

    426 posts

    If I understand you correctly it will depend on where you are using it and parse order.  You can always do something like below:

    {exp:query sql="SELECT cat_id as sub_cat_id FROM exp_categories WHERE parent_id = '{segment_3_category_id}' "}
    {sub_cat_id}
    {/exp:query}

    As for the delimiter try this:

    {exp:query sql="SELECT cat_id as sub_cat_id FROM exp_categories WHERE parent_id = '1' "}{sub_cat_id}|{/exp:query}
  • #3 / Oct 27, 2010 9:40am

    Rudy Affandi

    9 posts

    You are brilliant! I’ve added backspace=“1” to trim the excess pipe and it’s all set.

    Thanks!
    Rudy

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

ExpressionEngine News!

#eecms, #events, #releases