besly98 Posted May 14, 2009 Share Posted May 14, 2009 hi all im trying to use this code to say " if a number between 200 and 441 wright the random number but its not workign. can anyone help? elseif ($tactic == "442" && $rating >= 200 && $rating <= 441) { echo rand(0, 2); } Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/ Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 That looks fine, are you sure $tactic is "442" when your testing it? Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834028 Share on other sites More sharing options...
besly98 Posted May 14, 2009 Author Share Posted May 14, 2009 yes. does it need to be in " marks? Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834030 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 If its a number then no it wont need to be in "", however php will convert between a sting and number for you anyway so it doesn't matter to much. The only other thing I can think it could be is it's getting caught by an if statement further up. Have you got the whole chunk of code? Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834032 Share on other sites More sharing options...
besly98 Posted May 14, 2009 Author Share Posted May 14, 2009 this is the full code if ($tactic =="442" && $rating <= 200) { echo rand(0, 1); } elseif ($tactic == "442" && $rating >= 200 && $rating <= 441) { echo rand(0, 2); } elseif ($tactic == "442" && $rating >= 441 && $rating <= 550) { echo rand(0, 3); } elseif ($tactic == "442" && $rating >= 551 && $rating <= 660) { echo rand(0, 4); } elseif ($tactic == "442" && $rating >= 661 && $rating <= 770) { echo rand(0, 4); } elseif ($tactic == "442" && $rating >= 771 && $rating <= 880) { echo rand(1, 5); } elseif ($tactic == "442" && $rating >= 881 && $rating <= 990) { echo rand(1, 6); } elseif ($tactic == "442" && $rating >= 991) { echo rand(1, 7); } the number is 1000 so it shoudl get to the last if... but it doesnt print anything. and the tactic is 442 Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834034 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 IF I use this test data on that block of code it works fine. so it's not even getting to those set of statements by the looks of things. <?php $rating = 1000; $tactic = "442"; if ($tactic =="442" && $rating <= 200) { echo rand(0, 1); } elseif ($tactic == "442" && $rating >= 200 && $rating <= 441) { echo rand(0, 2); } elseif ($tactic == "442" && $rating >= 441 && $rating <= 550) { echo rand(0, 3); } elseif ($tactic == "442" && $rating >= 551 && $rating <= 660) { echo rand(0, 4); } elseif ($tactic == "442" && $rating >= 661 && $rating <= 770) { echo rand(0, 4); } elseif ($tactic == "442" && $rating >= 771 && $rating <= 880) { echo rand(1, 5); } elseif ($tactic == "442" && $rating >= 881 && $rating <= 990) { echo rand(1, 6); } if ($tactic == "442" && $rating >= 991) { echo rand(1, 7); } ?> Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834037 Share on other sites More sharing options...
besly98 Posted May 14, 2009 Author Share Posted May 14, 2009 hmmm bizar.. ok thanks. i guess its not comign from the database. altough i have tested that Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834038 Share on other sites More sharing options...
besly98 Posted May 14, 2009 Author Share Posted May 14, 2009 ahhhhhh i defined the string as tactic but tryed to reference it as tactics thats why Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834041 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 dam typos! Glad you got it sorted. Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834043 Share on other sites More sharing options...
besly98 Posted May 14, 2009 Author Share Posted May 14, 2009 thanks. its always a schoolboy error lol Link to comment https://forums.phpfreaks.com/topic/158117-pho-more-than-and-less-than/#findComment-834045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.