Danny696 Posted June 14, 2009 Posted June 14, 2009 how do i select a radom user i want it so on explore i can attack a random user it dm now as ive got it it was this if any1 wants it $q=$db->query("SELECT userid FROM users"); $membs=$db->num_rows($q); $randuser=(int) rand(1,$membs) then for me i wanted a random attack to it would be <a href='attack.php?ID=$membs>Attack Radom User</a> Quote
Cronus Posted June 14, 2009 Posted June 14, 2009 Re: random user The script you have there will not work. What if you have 300 members, but a few IDs have been deleted, and your rand() selects a deleted ID? You need this: $blah=mysql_query("SELECT * FROM users ORDER BY RAND() LIMIT 1"); $user=mysql_fetch_array($blah); Then the attacking line would be: [url='attack.php?ID={$user[']Attack Random User[/url] However, I don't know why a player would ever agree to attack someone completely random in the game lol. What if they get the #1 guy? Quote
Miniman Posted June 14, 2009 Posted June 14, 2009 Re: random user The script you have there will not work. What if you have 300 members, but a few IDs have been deleted, and your rand() selects a deleted ID? You need this: $blah=mysql_query("SELECT * FROM users ORDER BY RAND() LIMIT 1"); $user=mysql_fetch_array($blah); Then the attacking line would be: [url='attack.php?ID={$user[']Attack Random User[/url] However, I don't know why a player would ever agree to attack someone completely random in the game lol. What if they get the #1 guy? Thinking outside the box maybe? And why are you selecting the whole of users? If YOU have like 15,000 users, and your doing that, it's not good....lol Quote
Cronus Posted June 14, 2009 Posted June 14, 2009 Re: random user It only selects 1 user, ie the LIMIT 1. That query will take milliseconds to load. If you want it to just select userid you could i suppose, but since its only pulling 1 result it really won't matter all that much. Quote
Miniman Posted June 14, 2009 Posted June 14, 2009 Re: random user Just pointing out, if your doing that sort of select on everyone of your pages with the user base you have.....Ouch :-P Quote
Cronus Posted June 14, 2009 Posted June 14, 2009 Re: random user lol I actually use that query on an assortment of pages. :p It really doesn't take that many resources, as it doesn't ACTUALLY look at every row, just the 1 random one that it pulls. It is the equivalent of pulling the $ir value for the user that is actually playing. But nonetheless, its no big deal, just a wee little query. Not trying to start a huge debate. Quote
Danny696 Posted June 15, 2009 Author Posted June 15, 2009 Re: random user thanks people and this will only be on the explore page Quote
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.