Results 1 to 5 of 5

Thread: Displaying a random record from database

  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Displaying a random record from database

    OK. I need whoever answers this to answer as if they were writing Database for Dummies! I have a music website whichI have my reviews in an Access database running it through ASP. I need to create another area on a page that can randomly display the records in the database. How do I code that and do I place it at the space in the page where I want the record to appear? I need the step by step version on this. I am a brand newbie!

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    In SQL server 2000 we can do this

    select top 5 * from invsheet order by newID()

    Any random number generation depends on the system clock. So use the date time function to generate a number and match your primary key column.

  3. #3
    Join Date
    Apr 2003
    Posts
    3
    I don't understand you yet. I am brand new to ASP and one line of code doesn't mean much to me yet. I need a few steps on how to accomplish this within my webpage!

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254

    Thumbs up

    For example your table [Music] has columns and rows like this and
    if you like to create a 5 random rows.

    id MusicTitle Artist
    --------------------------------------------------
    1 All the things she said TATU
    2 In Da Club
    3 Pimp Juice
    4 Not Gonna Get Us TATU
    5 Bring Me To Life
    6 Get Busy
    7 I'm Glad
    8 Can't Let You Go...Damn
    9 Hot in here
    10 Eminem


    use this sql statement to return 5 rows in random. RND() function in MS-Access gets random values from System clock.

    SELECT TOP 5 [MusicTitle], [Artist]
    FROM MUSIC
    order by Rnd([ID]);

  5. #5
    Join Date
    Apr 2003
    Posts
    3
    Oh ok. I'll try that.

Posting Permissions

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