seany123 Posted July 24, 2009 Share Posted July 24, 2009 i currently have a page with this code in.. <?php $strrand = rand(1,100); $defrand = rand(1,100); $spdrand = rand(1,100); $bankrand = rand(1,100); $pointsrand = rand(1,100); //Strength success If($strrand <= 20) { echo "<br><b>Strength:</b> ". $english_format_number = number_format($enemy->strength) ."<br>"; } //Strength fail else if($strrand >= 21) { echo "<br><b>Strength:</b> Couldn't find out!<br>"; } //defense success If($defrand <= 20) { echo "<b>defense:</b> ". $english_format_number = number_format($enemy->defense) ."<br>"; } //defense fail else if($defrand >= 21) { echo "<b>defense:</b> Couldn't find out!<br>"; } //speed success If($spdrand <= 20) { echo "<b>speed:</b> ". $english_format_number = number_format($enemy->speed) ."<br>"; } //speed fail else if($spdrand >= 21) { echo "<b>speed:</b> Couldn't find out!<br>"; } //bank success If($bankrand <= 20) { echo "<b>bank:</b> ". $english_format_number = number_format($enemy->bank) ."<br>"; } //bank fail else if($bankrand >= 21) { echo "<b>bank:</b> Couldn't find out!<br>"; } //points success If($pointsrand <= 20) { echo "<b>points:</b> ". $english_format_number = number_format($enemy->points) ."<br><br>"; } //points fail else if($pointsrand >= 21) { echo "<b>points:</b> Couldn't find out!<br><br>"; } $query = $db->execute("update `players` set `money`=? where `id`=?", array($player->money - $moneyloss, $player->id)); echo "<a href=\"home.php\">Back</a>"; ?> what i want to do is put that information into a database... but i dunno the best way of doing it... i dont wanna have to do something like this... <?php if ($strrand >= x && $defrand <= x && $spdrand <= x && $bankrand <= x && $pointsrand <= x){ Then do query. } else if ($strrand <= x && $defrand >= x && $spdrand <= x && $bankrand <= x && $pointsrand <= x){ then do query } else if ($strrand <= x && $defrand <= x && $spdrand >= x && $bankrand <= x && $pointsrand <= x){ then do query } ?> because as you can see that could take forever... but i cant think of how i can do it. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 i don't understand where the 'x' comes into play...but would it help if you put them in an array and sorted them? that way $array[0] would give you the lowest and $array[4] would give you the highest? Quote Link to comment Share on other sites More sharing options...
seany123 Posted July 24, 2009 Author Share Posted July 24, 2009 i don't understand where the 'x' comes into play...but would it help if you put them in an array and sorted them? that way $array[0] would give you the lowest and $array[4] would give you the highest? i dont understand what you mean.. as for the X.. its just to show where a value is... in my case >= 21 <= 20 Quote Link to comment Share on other sites More sharing options...
vineld Posted July 24, 2009 Share Posted July 24, 2009 Yeah, well, he knew that He just wanted to know if there was any specific logic in the relation between x and the values that could help. Quote Link to comment Share on other sites More sharing options...
seany123 Posted July 24, 2009 Author Share Posted July 24, 2009 no, im just looking for a less time consuming way of doing this... without having to write out 25 different if statements. Quote Link to comment Share on other sites More sharing options...
vineld Posted July 24, 2009 Share Posted July 24, 2009 We have no idea how these values relate to each other which makes it difficult to suggest any other alternatives. You should try to find a pattern if possible. It seems as if the whole logic behind ending up in this situation is the actual problem. Quote Link to comment Share on other sites More sharing options...
seany123 Posted July 25, 2009 Author Share Posted July 25, 2009 these values dont relate to each other. for example $strrand $defrand dont relate to eachother.... all im doing is getting $strrand = rand(1,100); then echoing something if its >= 21 and something else if its <= 20. but i wanna update the answers the a table.. Quote Link to comment Share on other sites More sharing options...
seany123 Posted July 25, 2009 Author Share Posted July 25, 2009 also in mysql how can i make it so the same row can store int and varchars? Quote Link to comment Share on other sites More sharing options...
gizmola Posted July 25, 2009 Share Posted July 25, 2009 also in mysql how can i make it so the same row can store int and varchars? You can have whatever columns you want in a table. Each individual column can have it's own datatype. Other than that, we don't really have enough information about this application to understand what you're trying to do, or suggest alternatives. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.