ll87 Posted December 17, 2009 Report Share Posted December 17, 2009 I am using the script here: http://www.lateralcode.com/simple-php-gallery-pagination/ and trying to modify it so it works with my current image gallery (done differently to theirs) but after loading the first 12 images (first page), clicking on Next goes to page_no 1 but thats as far as it goes, and on page 1 (0 is the first) no pictures load. It's driving me nuts as i dont know which bit of code is messed up. can someone take a look? PHP (gallery_images.php): <?php $country = $_GET['trip']; $directory = 'Images/'.$country; //folder of gallery photos. $thumbs_dir = 'thumbs'; $_thumbs = "_thumb."; //to add to end of each thumbnail's name. $allowed_types = array('jpg','jpeg','gif','png'); $file_parts = array(); //consists of file name and extension. $title = ''; //First part of file parts. $ext = ''; //Second part of file parts. $i = 0; //Iterator to check for last (fourth) image in each row. $per_page = 12; $has_previous = false; $has_next = false; $page_no = $_GET['page_no']; //try to open directory. $dir_handle = opendir($directory) or die("Cannot open directory."); $count = 0; $skip = $page_no * $per_page; if($skip != 0){ $has_previous = true; } while($count < $skip && $file = readdir($dir_handle)) { if(!is_dir($file) && in_array($ext,$allowed_types)) { $count++; } } echo 'page number = '.$page_no; $count = 0; //while($count < $per_page && $file = readdir($dir_handle)) //{ // if(!is_dir($file) && in_array($ext,$allowed_types)){ // $count++; // } //} while($count <= $per_page && $file = readdir($dir_handle)) //Look through folder. { if($file == '.' || $file == '..') continue; //Ignore these files. $file_parts = explode('.',$file); //Split file into its parts and put into array. $ext = strtolower(array_pop($file_parts)); //Puts last item of array into ext. if(in_array($ext,$allowed_types)){ $title = implode('.',$file_parts); //ext has been popped off, so all that remains is title of file. $title = htmlspecialchars($title); //Make title html safe if it isn't already. //Create image to create thumbnail from. $img = imagecreatefromjpeg($directory.'/'.$file); $width = imagesx($img); $height = imagesy($img); //Create thumbnails. $new_width = 150; $new_height = floor($height * ($new_width / $width)); //Creates proportionally correct new height according to new width. floor rounds down to integer. //Create new image with new dimensions to hold thumb $tmp_img = imagecreatetruecolor($new_width,$new_height); //Copy and resize original image into new image. imagecopyresampled($tmp_img,$img,0,0,0,0,$new_width,$new_height,$width,$height); //Store image in a directory if(!is_dir($directory.'/'.$thumbs_dir)) { mkdir($directory.'/'.$thumbs_dir); } imagejpeg($tmp_img,$directory.'/'.$thumbs_dir.'/'.$title.$_thumbs.$ext); //echo '';//'; $nomargin = ''; //Variable for last image of each row. if(in_array($ext,$allowed_types)) //If file is an allowed file type. { //echo ' //'.$title.''; if(($i+1)%4==0) $nomargin = 'nomargin'; //i begins at 0 so add one to correspond to first image. If it is divisable by 4, it //the last of the row, so give special class of nomargin. echo ' '.$title.''; //echo ''; $i++; //Next iteration we are looking at next image. } } $count++; } while($file = readdir($dir_handle)) { if(!is_dir($file) && in_array($ext,$allowed_types)) { $has_next = true; break; } } closedir($dir_handle); //close the directory. ?> PHP (gallery_content.php): <?php include 'gallery_images.php'; ?> <?php if($has_previous){ echo 'Previous'; } if($has_next){ echo 'Next'; } ?> Quote Link to comment Share on other sites More sharing options...
ll87 Posted December 22, 2009 Author Report Share Posted December 22, 2009 no one? Quote Link to comment Share on other sites More sharing options...
jlhaslip Posted December 22, 2009 Report Share Posted December 22, 2009 http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=pagination+scripts+php 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.
Note: Your post will require moderator approval before it will be visible.