Jump to content
MakeWebGames

Recommended Posts

Posted
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>
Posted

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?

Posted

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

Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...