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.

help with nested gallery queries

February 03, 2009 1:53pm

Subscribe [1]
  • #1 / Feb 03, 2009 1:53pm

    bobh

    145 posts

    hi all,

    I’ve been using the well documented ‘Gallery Category Images’ method to pull my 4 latest gallery categories and an accompanying random image. In short, it wraps the exp:gallery:entries tags with a query.

    I would now like to make a variation in which only random portrait images are pulled. This means abandoning the exp:gallery:entries tags and replacing them with a second query which enables me to pull witdh & height values.

    Unforunately the query isn’t behaving like I was expecting it to:

    {exp:query sql="SELECT c.cat_id as cat1 FROM exp_gallery_categories as c WHERE gallery_id='1' ORDER BY cat_id DESC LIMIT 4"}
        {exp:query sql="SELECT entry_id FROM exp_gallery_entries WHERE cat_id='{cat1}' ORDER BY RAND() LIMIT 1"}
            {entry_id}
    
        {/exp:query}
    {/exp:query}

    To my surprise the above code renders 4 times the same entry_id in stead of 4 random entry_id’s each from a different category.

    What am I doing wrong here?

  • #2 / Feb 03, 2009 4:29pm

    Lisa Wess

    20502 posts

    Hi bobh - to nest like that you’ll need to embed your inner query tags and pass the information through an embed.

  • #3 / Feb 03, 2009 4:30pm

    Greg Aker

    6022 posts

    bob:

    Since this is coming from the community wiki, I’m going to move it over to “how to” as it is a better fit.

    Thanks,

    -greg

  • #4 / Feb 03, 2009 4:49pm

    bobh

    145 posts

    Thanks guys, this works perfectly.

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

ExpressionEngine News!

#eecms, #events, #releases