blueman378 Posted December 16, 2007 Share Posted December 16, 2007 hi guys i am making a games website and i need a code to for the WHERE part of the mysql query it selects a random value from a column called gname so basically i want a code to read the info from gname, and select one at random, or sequential, is this possible? thanks PS: im not asking for a complete code just some pointers to the right functions ect thanks people Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 16, 2007 Share Posted December 16, 2007 SELECT * FROM gname ORDER BY rand() Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 16, 2007 Share Posted December 16, 2007 i your looking for only one result: SELECT * FROM gname ORDER BY rand() LIMIT 1 Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 20, 2007 Author Share Posted December 20, 2007 so say i had 20 results would it keep running till it found one that matched? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 20, 2007 Share Posted December 20, 2007 so say i had 20 results would it keep running till it found one that matched? What do you mean until it found one that matched? What are you trying to match? Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 24, 2007 Author Share Posted December 24, 2007 the id colum, so for example i have ids between 1-20, rand can generate large numbers so would i have a while mysql affected rows = 0 rerun the query? else run my code with the generated results? how would i go about this? thanks Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 24, 2007 Share Posted December 24, 2007 rand() is not going to choose anything that isn't in your table, so you will always have a result. Quote Link to comment Share on other sites More sharing options...
blueman378 Posted December 25, 2007 Author Share Posted December 25, 2007 oh ok thanks alot mate Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted December 25, 2007 Share Posted December 25, 2007 Does that solve your problem? If so, please mark the thread as solved. 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.