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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2004
    Location
    Los Angeles, CA
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    random selection out of MySQL results

    Hello,

    I'm trying to do a random selection out of a MySQL query with a specific conditional. Example: I have a table that has an item id and the price for each item. I query for all items over a certain price and it returns a series of ids that fit that criteria. Then I need to randomly choose from these returned ids in order to display a random item with that criteria. Any methods or suggestions on how to specifically implement this would be greatly appreciated!

    Thanks, Jay

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    mysql_query("SELECT product FROM table WHERE id='id_number' ORDER BY RAND() LIMIT 1")

    Give that a try


  •  

    Posting Permissions

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