Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-31-2005, 02:50 PM random?
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
Say if i had a mysql table called 'items', with fields 'ID', 'item_name' and 'rarity' how could i pick a random item thats rarity is lower than 80?
timsquash5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-31-2005, 02:56 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
PHP Code:
$result mysql_query("SELECT * FROM items WHERE rarity < 80 ORDER BY RAND() LIMIT 1");
$item mysql_result($result,0,'item_name'); 
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-31-2005, 03:04 PM
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
another thing, say if i had a table called users and fields called ID, name and tickets

how would i add up the total number of tickets then find a random number and echo that username, so if a person has more tickets they are more likely to be choosen?
timsquash5 is offline
Reply With Quote
View Public Profile
 
Old 03-31-2005, 03:11 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
For that I'd use a very similar approach to the one for picking your shop items randomly based on how rare they are. Add up the total tickets:

Code:
SELECT SUM(tickets) FROM users
Read out the users into an array, then in php generate a random number and add to it each users ticket number. When you exceed that ticket number, use that user. It's exactly the same as the shop code from your other thread except you don't invert the ticket number (more tickets is more likely whereas LESS rarity is more likely).
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-31-2005, 03:14 PM
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
With your first example i get:

Quote:
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 12 in /home/hsphere/local/home/cordy/simupets.com/random_item1.php on line 62
timsquash5 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to random?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14548 seconds with 12 queries