johngary Posted August 13, 2009 Share Posted August 13, 2009 I'm bit new to php and I got this code on my site but however Id like this to change the images to show up in the right order of sequence. My images are number from 1.jpg, 2.jpg and so on but on my site it appears to be in random... Anyone please can fixed this... <?php $p = $_GET['p']; if ($handle = opendir("images/rootfolder/")) { $i = 1; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $img[$i] = $file; if ($p == $img[$i]) { $ci = $i; } $i++; } } closedir($handle); $ti = $i - 1; $pi = $ci - 1; if ($p == "") { $ni = $ci + 2; } else { $ni = $ci + 1; } $prevNext = ""; if ($pi > 0) { $piFile = $img[$pi]; $prevNext .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $piFile . "\" title=\"show previous image\">Previous</a>"; } else { $prevNext .= "Previous"; } $prevNext .= " | "; if ($ni <= $ti) { $niFile = $img[$ni]; $prevNext .= "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=" . $niFile . "\" title=\"show next image\">Next</a>"; } else { $prevNext .= "Next"; } if ($p == "") { $p = $img[1]; } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 13, 2009 Share Posted August 13, 2009 Please post code in code tags, it makes it easier to read. You have an array of images called $img, but I don't see you using sort() anywhere. Quote Link to comment Share on other sites More sharing options...
johngary Posted August 13, 2009 Author Share Posted August 13, 2009 Sorry for that just new to forums.....can you do any changes with sorting codes on my script? thanks. Quote Link to comment 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.