JayLewis Posted February 21, 2007 Share Posted February 21, 2007 Hey my problem is: The user types in there name and hits sumbit. Then i use this code to generate a random number. I want an If statement for example "49% = "Under 50%" and "51%+ = 50% Plus" I am using this code to do so, but the If statements seems to be random also. You and <?php echo $_POST["name"]; ?> are <? srand((double)microtime()*1000000); echo rand(0,100); echo "% compatible!"; $number = rand(0,100); if ($number < 49) { echo "</b><br>Under 50%"; } else { echo "</b><br>50% Plus"; } ?> Link to comment https://forums.phpfreaks.com/topic/39532-posting-a-random-number-with-if-statements/ Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 echo rand(0,100); echo "% compatible!"; $number = rand(0,100); You're getting two different rand() numbers. So they won't be the same. $per = rand(0,100); echo $per; if($per< 50){ }else{ } Link to comment https://forums.phpfreaks.com/topic/39532-posting-a-random-number-with-if-statements/#findComment-190755 Share on other sites More sharing options...
kenrbnsn Posted February 21, 2007 Share Posted February 21, 2007 You're getting two random number, when (I think) you only want one: <?php echo 'You and ' . $_POST["name"] .' are'; $number = rand(0,100); echo $number . '% compatible!'; if ($number < 50) echo "</b><br>Under 50%"; else echo "</b><br>50% Plus"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/39532-posting-a-random-number-with-if-statements/#findComment-190756 Share on other sites More sharing options...
JayLewis Posted February 21, 2007 Author Share Posted February 21, 2007 Thanks alot people! Works a treat... Greatly appreciated. I'm getting better ... Thanks to you guys! Link to comment https://forums.phpfreaks.com/topic/39532-posting-a-random-number-with-if-statements/#findComment-190759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.