Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: ORDER by random

  1. #1
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post

    ORDER by random

    Is there a way of ordering a selected database randomly?
    If so does anyone know the string I would have to use for this?

    Thanks.

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    There is no Order By Random kind of clause if that's what you're asking. What exactly are you trying to do?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by vinyl-junkie
    There is no Order By Random kind of clause if that's what you're asking. What exactly are you trying to do?
    I didn't think there would be that kind of clause. I want to select the database and order it in a random order. I will only be displaying the first row on my homepage so that I can display an image which links to a full size version on another page.

    Thanks.

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Will you be displaying things in random order or just selecting the first record randomly? If selecting the first record randomly, by an id for example, just come up with a random number generator and select the one record using that random number.

    What language are you using to code your page?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    Quote Originally Posted by vinyl-junkie
    Will you be displaying things in random order or just selecting the first record randomly? If selecting the first record randomly, by an id for example, just come up with a random number generator and select the one record using that random number.

    What language are you using to code your page?
    Im using VB

    I would prefer not to do it that way because I have deleted records, so some IDs are missing.

  • #6
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    I'm thinking off the top of my head here, but I think you could load all your records into an array, then randomly pick one record from the array for display.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #7
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Are you using access? If so, have a look at the Rnd() function.

    Good luck;

  • #8
    Regular Coder CurtWRC's Avatar
    Join Date
    May 2005
    Location
    UK
    Posts
    224
    Thanks
    9
    Thanked 1 Time in 1 Post
    I may be wrong but wouldn't this just be selecting a random number between certain values. So if I had deleted a record with ID of 8, then if 8 was randomly selected nothing would appear

  • #9
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting a random record from an Access databse

    I'm assuming your using coldfusion. So if you are, his might be usefull:

    ________________________________________________________________

    <!---first set the query --->
    <cfquery name="rs" datasource="#dsn#">
    SELECT [column_names(s)]
    FROM [table_name]
    </cfquery>


    <!--- then use the output to display randomly --->
    <cfset displayRow = randRange(1,rs.recordcount)>
    <cfoutput query="rs" startrow="#displayRow#" maxrows="1">
    -- show the random record
    </cfoutput>



    Hope this helps.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •