lanu Posted December 29, 2011 Share Posted December 29, 2011 Hi there, My code here is meant to take the variable "$beyondportal" and see if it is a multiple of 26 counting from 0, then from 1, 2, 3 etc.. all the way to 25. if it's a multiple of 26 counting from 1, I get a set of content. If it's a multiple of 26 counting from 1, I get another all the way through 25. The code I wrote is working great if $beyond portal turns out to be a positive value, but if it's a negative value, this seems to be coming up wrong except for in the case of multiples of 26 counting up from 0 because -26 is the same distance as 26 from zero. Can someone see the pattern I'm getting at here? <?php if ($beyondportal % 26 == 0 || $beyondportal == 0 || abs($beyondportal) % 26 == 0){ ?> PURPLE <?php } ; ?> <?php if ($beyondportal % 26 == 1 || $beyondportal == 1|| abs($beyondportal) % 26 ==1){ ?> BLUE <?php } ; ?> <?php if ($beyondportal % 26 == 2 || $beyondportal == 2|| abs($beyondportal) % 26 ==2){ ?> GREEN <?php } ; ?> ETC... ETC.... up to: <?php if ($beyondportal % 26 == 25 || $beyondportal == 25|| abs($beyondportal) % 26 ==25){ ?> YELLOW <?php } ; ?> (my code on 1-25 is coming up incorrectly) Quote Link to comment https://forums.phpfreaks.com/topic/254001-counting-troubles/ Share on other sites More sharing options...
sasa Posted December 29, 2011 Share Posted December 29, 2011 change <?php if ($beyondportal % 26 == 0 || $beyondportal == 0 || abs($beyondportal) % 26 == 0){ ?> PURPLE <?php } ; ?> to <?php if ($beyondportal % 26 == 0){ ?> PURPLE <?php } ; ?> or <?php if (abs($beyondportal) % 26 == 0){ ?> PURPLE <?php } ; ?> for all sace Quote Link to comment https://forums.phpfreaks.com/topic/254001-counting-troubles/#findComment-1302111 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.