Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

OrderBy Rand?

edited February 2012 in Vanilla 2.0 - 2.8

Hello.
Currently i'm trying to get 10 random records out of my table. I figured doing the following would work, but it doesn't. Anyone give me some help?

$Games = $this->SQL->Select() ->From('Games') ->Limit($Limit) ->OrderBy('GameID', 'rand()');

Best Answer

Answers

  • jspautschjspautsch Themester ✭✭✭
    Answer ✓

    It's just ->OrderBy('RAND()');

  • Perfect! Thank you for that, I had a feeling it'd be something simple.

  • @jspautsch Thanks again, it's looking perfect for what I wanted to do. Do you happen to know if there is an autocomplete library built in? I know I have seen autocomplete somewhere in Vanilla before but I can't remember where.

    FYI: The background games change every reload :D

  • jspautschjspautsch Themester ✭✭✭
    edited February 2012

    Autocomplete is used in Conversations, looking through that you can find the following javascript:

       // Enable multicomplete on selected inputs
       $('.MultiComplete').livequery(function() {
          $(this).autocomplete(
             gdn.url('/dashboard/user/autocomplete/'),
             {
                minChars: 1,
                multiple: true,
                scrollHeight: 220,
                selectFirst: true
             }
          ).autogrow();
       });
    

    So that's to autocomplete usernames, haven't tried it with anything else.

    And then you need to have your theme or plugin include the jquery.autocomplete.js file on whatever page you want to use it on.

Sign In or Register to comment.