hi there, im on a image gallery here, and i wanna display x new thumbs per day. if i dont have any new images to show, i wanna go back to the first picture and start over again. so if i have 10 images and wanna show 4 new each day, i must display: day1: 1-4 day2: 5-8 day3: 1-4 (forget 9 and 10, just start over again) day4: 5-8 ... every thumb has a database entry, and for this problem i have this values: $thumbrate - number of thumbs to show each day, 4 in this case $age - age of this gallery in days $counter - total number or thumbs in this category, 10 here i need: $offset, the number of results to skip, must be 0 for day1 and day3, 4 on day 2 and day 4. can someone think about a formula to solve this problem please, or contact me on icq? thanks...
// how many have we already shown? if ( $age ) { $alreadyShown = $age*$thumbrate; // show next or start over? if ( $alreadyShown+$thumbrate < $counter ) { $offset = $alreadyShown; } else { $offset = 0; } } else { $offset = 0; } PHP: I think that works... assuming $age starts at 0 rather than 1.
hm ok, you solved the easy part - the problem is after "else": that keeps it forever on $offset=0 after the first circle - but it should repeat the whole gallery over and over again.
You're right, my fault. Working version: // if age is 0, offset 0, otherwise... if ( $age ) { // days for a cycle $daysPerCycle = floor($counter/$thumbrate); // days occured so far in current cycle $inCurrent = $age % $daysPerCycle; // images already shown in this cycle $alreadyShown = $inCurrent*$thumbrate; // show next or start over? if ( $alreadyShown+$thumbrate < $counter ) { $offset = $alreadyShown; } else { $offset = 0; } } else { $offset = 0; } PHP: Hopefully that's better.