homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Point looping

 9:57 pm on Sep 12, 2012 (gmt 0)


I'm not sure what this is called, if there is an algorithm for this so have had troubles searching for it.

It seems pretty basic but I seem to keep getting stuck in the same place.

I have points and I have a point threshold, as points keep getting accumulated (which is a different number each time) I need to determine if the current points have just passed the threshold or not. So say I have 489 points, then the next amount of points brings the total to 511 points and my max is 500, I have a remainder of 11.

Here's my PHP code:

$current_points = 511;
$min_points = 500;

if($current_points > $min_points){
$points_multiple = $current_points % $min_points;

if($points_multiple > 0){
$points_needed = $min_points - $points_multiple;
$points_needed = 0;
$points_needed = $min_points - $current_points;

Note: The next time this threshold is reached would be after 1000 points, and $min_points could be changed at anytime.

I do have access to the number of points per transaction, so I was thinking I could get that last number and subtract it from the current and if $points_multiple is over the threshold cycle but $current_points - $last_points is under, then I know it has just passed the threshold, but I'd like to know if there's a better way.




 7:05 pm on Sep 13, 2012 (gmt 0)

Not sure I understand the whole issue here. Doesn't this work?

$currentPoints = 511;
$threshold = 500;

if($currentPoints > $threshold) {
echo 'Passed threshold';
$threshold += 500; // increase threshold value


 7:48 pm on Sep 13, 2012 (gmt 0)

I ended up solving the problem by using the method I stated above. Thanks though.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved