sdowney1 Posted February 27, 2011 Share Posted February 27, 2011 can this be improved? I can increment every 20, and there will never be more than 10,000 record count $count = 1; while ($count <= 10000) { if (($rpos>=$count) and ($rpos<($count+20))){$dum = $count;break;} $count =($count +20); } echo 'weirdcounter'.$dum.'<BR>'; Quote Link to comment https://forums.phpfreaks.com/topic/229074-looking-for-an-algorithm-for-number-progression-is-now-working-but/ Share on other sites More sharing options...
MattDunbar Posted February 27, 2011 Share Posted February 27, 2011 The if statement has a few more brackets than it needs, this would suffice: if ($rpos>=$count && $rpos<($count+20)) I'm not really sure if it can be improved. You'd need to explain the purpose of the code. Quote Link to comment https://forums.phpfreaks.com/topic/229074-looking-for-an-algorithm-for-number-progression-is-now-working-but/#findComment-1180580 Share on other sites More sharing options...
sdowney1 Posted February 28, 2011 Author Share Posted February 28, 2011 Thanks for the help On one page, I display a series of records in 20 record blocks, with pagination. Basically, every next, previous, etc... shows another 20 record set. I create a link displayed with each record based on the record number which is part of each record. Click that it loads another page which displays just that one record. On that page I move forward or back one record at a time. SO, when I post back to the first page that displays the 20 record set, I needed to figure out which set of 20 records to display. I modified what the algorithm needs to this I need to take in a number from 1 -> 20 and return 1 21 -> 40 and return 21 41 -> 60 and return 41 61 -> 80 and return 61 etc.... so if your displaying record number 15, it posts back to block of records starting at 1 running to 20 so if your displaying record number 25, it posts back to block of records starting at 21 running to 40 Quote Link to comment https://forums.phpfreaks.com/topic/229074-looking-for-an-algorithm-for-number-progression-is-now-working-but/#findComment-1180722 Share on other sites More sharing options...
sdowney1 Posted March 1, 2011 Author Share Posted March 1, 2011 got it with some help on ubuntuforums $dum = (($rpos-1)/20) ; $dum = (int)($dum); $dum = (($dum *20) +1); Quote Link to comment https://forums.phpfreaks.com/topic/229074-looking-for-an-algorithm-for-number-progression-is-now-working-but/#findComment-1181608 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.