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]; } } ?> Link to comment https://forums.phpfreaks.com/topic/170119-how-sort-my-images-on-this-php-script/ 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. Link to comment https://forums.phpfreaks.com/topic/170119-how-sort-my-images-on-this-php-script/#findComment-897390 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. Link to comment https://forums.phpfreaks.com/topic/170119-how-sort-my-images-on-this-php-script/#findComment-897414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.