Change to a cyclic unlimited while loop

Bufffluopsy

New Member
I have a photo gallery that has a previous and a Next link. When it gets to the last image it stops there. I want it to start over at the first picture. The function is a for loop and I think it should be a while loop and some things changed to make it an infinite loop. I just don't know how to convert this function. Still not that strong in PHP. Any help is appreciated.\[code\]$query = "SELECT pho_id FROM album_photos WHERE alb_id='$alb_id' ORDER by srt_id ASC"; $ret = mysql_query($query); $num = mysql_numrows($ret); for ($i = 0; $i < $num; $i++) { $row = trim(mysql_result($ret, $i)); if ($row == $pho_id) { $cur = $i; $forw = @trim(mysql_result($ret, ($i+1))) or $forw = NULL; $back = @trim(mysql_result($ret, ($i-1))) or $back = NULL; } }$query = "SELECT * FROM photos WHERE pho_id='$back'"; $rets = mysql_query($query); $back_good = mysql_numrows($rets); $query = "SELECT * FROM photos WHERE pho_id='$forw'"; $rets = mysql_query($query); $forw_good = mysql_numrows($rets); $back = "photo-$per_id-$back-$alb_id.html"; $forw = "photo-$per_id-$forw-$alb_id.html"; if (strstr($back, 'pho_id=&') || $back_good == 0) { $back = NULL; } if (strstr($forw, 'pho_id=&') || $forw_good == 0) { $forw = NULL; } $ret = array(); $ret['back'] = $back; $ret['next'] = $forw; $cur++; $ret['viewing'] = "Photo $cur of ".($num); if($ret['back'] == NULL){ $ret['back'] = ""; $spacer = str_repeat('&nbsp;',12); } if($ret['next'] == NULL){ $ret['next'] = ""; $spacer = str_repeat('&nbsp;',12); }\[/code\]
 
Back
Top