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"; } ?> Quote Link to comment 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{ } Quote Link to comment 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 Quote Link to comment 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! 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.