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.

Sort order by random?

August 12, 2010 11:02pm

Subscribe [2]
  • #1 / Aug 12, 2010 11:02pm

    o0S0o

    9 posts

    Hi. I’m creating a thumbnail page of all my members and I’d like to sort the images randomly. How can I do that? I’ve tried sort=“random” and orderby=“random” and neither work.  Here’s the code I’m trying to apply it to:

    <div class="album">
                {exp:query sql="SELECT member_id FROM exp_members WHERE (group_id = '6' OR group_id = '1' OR group_id = '7')"}
                    {exp:member:custom_profile_data member_id="{member_id}"}
                        {!--The switch variable handles applying the required different css to every other entry --}    
            
                        
        <div class="imageSingle">
                            <div class="image"><div id="tooltip"><a href="http://{path=staff/profile}{member_id}/">{exp:imgsizer:size image="{photo_url}" greyscale="yes" width="120px" height="120px" alt="{screen_name}" border="0"}</a></div></div>
                                                </div>
    
                    {/exp:member:custom_profile_data} 
                {/exp:query} 
    
            </div>

    Thanks!

  • #2 / Aug 13, 2010 7:33am

    tidy

    196 posts

    If you add order by rand() to the end of your custom query SQL, that should return the member ids in random order:

    {exp:query sql="SELECT member_id FROM exp_members WHERE (group_id = '6' OR group_id = '1' OR group_id = '7') order by rand()"}

    Hope this helps 😊

  • #3 / Aug 13, 2010 4:36pm

    o0S0o

    9 posts

    Works great! Thanks so much!

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

ExpressionEngine News!

#eecms, #events, #releases