Jump to content

[SOLVED] Randomly Select a Row


codexx

Recommended Posts

Hey Everyone,

 

I have to do a script where a user fights an enemy. There are many to choose from all for differn't levels in which the user is at.

 

I need to first (SELECT * FROM creep_data WHERE minlvl < '".$user[lvl]."' AND maxlvl > '".$user['lvl']."'")

 

After I have all of the possible monsters I need to randomly select one of these and retrieve all of the data about it.

 

How could I go about doing this :)?

 

Thanks in advance,

Sean

Link to comment
Share on other sites

Primary key is ID.

 

When I try $creepinfo = mysql_query ("SELECT * FROM creep_data WHERE minuserlvl < '".$user[lvl]."' AND maxuserlvl > '".$user['lvl']."' ORDER BY id rand()");

 

it gives me an error. Is there anyway I could get all off the possible creeps then randomly select on in an array?

Link to comment
Share on other sites

im still trying to get a hang of this php stuff myself, but try this, it should work.

 

$creepinfo = mysql_query ("SELECT * FROM creep_data WHERE minuserlvl < '$user[\'lvl\']' AND maxuserlvl > '$user[\'lvl\']' ORDER BY id rand()");

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.