widget Posted December 16, 2007 Share Posted December 16, 2007 I have a database table called items containing id, item_name, item_id, rarity etc etc. I would like to be able to extract items from my table based on their rarity and then randomly choose one of these items. something along the lines of $prize = fetch("SELECT item_id FROM items WHERE rarity = '7'"> then some code that grabs just one random item_id Any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted December 16, 2007 Share Posted December 16, 2007 http://dev.mysql.com/doc/refman/5.0/en/select.html - take a look at the user comments (starting at the 2nd comment). There are a couple post concerning selection of random rows. Quote Link to comment Share on other sites More sharing options...
widget Posted December 17, 2007 Author Share Posted December 17, 2007 Thanks for pointing me in the right direction. Not a lot of it made sense but.. This code should work? $prize = mysql("SELECT item_id FROM items WHERE rarity = '7' ORDER BY RAND() LIMIT 1"> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.