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
https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/
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

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!

Archived

This topic is now archived and is closed to further replies.

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