Jump to content

looking for an algorithm for number progression is now working but


sdowney1

Recommended Posts

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>'; 

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.