Canadiengland Posted March 18, 2007 Share Posted March 18, 2007 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 More sharing options...
AndyB Posted March 18, 2007 Share Posted March 18, 2007 $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 https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/#findComment-210170 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 how would i impliment that into my code? i tried usings yours.. didnt work. tried using the ORDER by rand LIMIT 1 in my code... didnt work. im stuck! Link to comment https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/#findComment-210343 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 bump Link to comment https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/#findComment-210390 Share on other sites More sharing options...
btherl Posted March 19, 2007 Share Posted March 19, 2007 In what way did it not work? Did it give an error message, or did it not act like you expected? Details please Link to comment https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/#findComment-210391 Share on other sites More sharing options...
Canadiengland Posted March 19, 2007 Author Share Posted March 19, 2007 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 https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/#findComment-210393 Share on other sites More sharing options...
AndyB Posted March 19, 2007 Share Posted March 19, 2007 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 https://forums.phpfreaks.com/topic/43279-random-selections-with-some-limitations/#findComment-210411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.