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. Link to comment https://forums.phpfreaks.com/topic/81915-randomising-a-database-item-help-please/ 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. Link to comment https://forums.phpfreaks.com/topic/81915-randomising-a-database-item-help-please/#findComment-416211 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"> Link to comment https://forums.phpfreaks.com/topic/81915-randomising-a-database-item-help-please/#findComment-416747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.