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.

Channel Entry tag inside a Query tag only works on index (first segment) pages.

April 25, 2012 8:35am

Subscribe [1]
  • #1 / Apr 25, 2012 8:35am

    CRHain

    8 posts

    Hello.

    I’m trying to build an embed code that will query a database and then show matched results. This will end up being for geo-location.

    Below is a simplified snippit of my code.

    {exp:query sql="SELECT entry_id FROM exp_matrix_data WHERE col_id_32 = 'NJ' LIMIT 1"}
    
      {if no_results}
        Sorry, there is no rep in your area. Please call the main office for help.
      {/if}
    
      {exp:channel:entries channel="rep_info" entry="{entry_id}" limit="1"}
    
        {!-- These will not show up on category or entry pages --}
        {title}, {matrix_field}{matrix_field_column}{/matrix_field}
    
      {/exp:channel:entries}
    
    {/exp:query}

    I’m able to get the “no_results” to display, but I cannot get matched results to show on any pages deeper then than the second segment. For example, the code will work on url.com/template_group, but not on url.com/template_group/category/category_title or url.com/template_group/template/entry_id.

    Is there anyway that I can fix this? The root of the situation is that I need to be able to display all content for any matched entry_id that I get from my query, including data inside the matrix form filed.

    Running EE2.4

    Edit:
    This wasn’t really working. I just happened to pull the most recent entry that matched my test condition, and no entry when there wasn’t any success. When I add more that doesn’t meet the conditions, it show’s the most recently added picture.

    Any ideas on how I can use query string with matrix to get the data I want to display? Also, I fixed the entry=”{entry_id}”

  • #2 / Apr 26, 2012 12:16pm

    Dan Decker

    7338 posts

    Hi CRHain,

    Thanks for posting your questions!

    We don’t typically offer support for SQL or third-party add-ons, but I may have a suggestion that can get you on track.

    You can try assigning entry_id as a different variable:

    {exp:query sql="SELECT entry_id as m_entry_id FROM exp_matrix_data WHERE col_id_32 = 'NJ' LIMIT 1"}
    
      {if no_results}
        Sorry, there is no rep in your area. Please call the main office for help.
      {/if}
    
      {exp:channel:entries channel="rep_info" entry_id="{m_entry_id}" limit="1"}
    
        {!-- These will not show up on category or entry pages --}
        {title}, {matrix_field}{matrix_field_column}{/matrix_field}
    
      {/exp:channel:entries}
    
    {/exp:query}

    By assigning it that way, you can make sure it’s not being overridden by channel entries.

    Let me know what you think!

    Cheers,

  • #3 / Apr 26, 2012 1:28pm

    CRHain

    8 posts

    Hi Dan.

    Thanks for your help. This solved my issue.

    This is after the fact, and although my example was a little simplified, no data was being passed back to the exp:channel:entries tag pair including regular custom fields.

  • #4 / Apr 30, 2012 3:09pm

    Dan Decker

    7338 posts

    Hi CRHain,

    Awesome, glad I was able to help!

    If you need anything else in the future, feel free to open a new thread.

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases