Jump to content

random selections with some limitations


Canadiengland

Recommended Posts

how would i make this select a random match for the code but stay within the limiations of rarity?

 

if ($randomitem<$itemget)
			{
			$item1="SELECT * from km_items where rarity<'$selmonster3[rare]' and raritymax>'$selmonster[rare]'";
    				$item2=mysql_query($item1) or die ("Could not find player");
    				$item3=mysql_fetch_array($item2);
			$randompower=rand(90,110) / 100;
       				$itempower=$item3[power]*$randompower;

			$createitem="INSERT into km_items (name, power, type, expperturn, rageperturn, itempic, owner, status, cost, rarity) VALUES ('$item3[name]', '$itempower', '$item3[type]', '$item3[expperturn]','$item3[rageperturn]','$item3[itempic]', '$playerstats3[playername]', 'u', '$item3[cost]', '$item3[rarity]')";
     				   mysql_query($createitem) or die("Could not create item");
       					 print "<center>You've found a(n) $item3[name]<br></center>";
				 print "<center><A href='index.php'>Kill more monsters</a></center>";

 

would i change SELECT to random select or something?

Link to comment
Share on other sites

well the main code is

(without his code)

 

$item1="SELECT * from km_items where rarity<'$selmonster3[rare]' and raritymax>'$selmonster[rare]'";

    $item2=mysql_query($item1) or die ("Could not find player");

    $item3=mysql_fetch_array($item2);

 

it kept displaying Could not find player... meaning it couldnt query it with the added order and limit included

Link to comment
Share on other sites

Apologies for my careless typing.  This is what I should have given (rand used properly!):

 

$query = "SELECT * from km_items where rarity<'$selmonster3[rare]' and raritymax>'$selmonster[rare]' ORDER by rand() LIMIT 1";

 

Returns one result .... now that I've corrected it!

Link to comment
Share on other sites

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.