HerrPNut Posted October 21, 2008 Share Posted October 21, 2008 Hello to everyone! I am setting up a site in php and I came across a problem. I made a photo-album without SQL, only php. At the moment all the photos are displayed on 1 page, but I tought it would be better with pagination (after 12 photos) Is it possible without SQL? ifzo how can i do it? cheers Robin Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/ Share on other sites More sharing options...
MasterACE14 Posted October 21, 2008 Share Posted October 21, 2008 of course its possible, but I for one, haven't attempted it without SQL before. I would imagine the best way to keep track of everything would be to use Session variables, and GET's as if it was SQL based pagination. Post your script. Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670761 Share on other sites More sharing options...
DeanWhitehouse Posted October 21, 2008 Share Posted October 21, 2008 If you hard coded the photos you will most likely need to hard code the pagination. You may be able to do it using arrays? Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670762 Share on other sites More sharing options...
JasonLewis Posted October 21, 2008 Share Posted October 21, 2008 Sure its possible. Say you have a folder full of images that you want to paginate. Here is a script I have that does just that. <?php //The directory to your images folder, with trailing slash $dir = "images/"; //Set the extensions you want to load, seperate by a comma. $extensions = "jpeg,jpg"; //Set the number of images you want to display per page $imagesPerPage = 1; //Set the $page variable if(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; } //Load all images into an array $images = glob($dir."*.{".$extensions."}", GLOB_BRACE); //Count the number of images $totalImages = count($images); //Get the total pages $totalPages = ceil($totalImages / $imagesPerPage); //Make sure the page you are on is not greater then the total pages available. if($page > $totalPages){ //Set the currnet page to the total pages. $page = $totalPages; } //Now find where to start the loading from $from = ($page * $imagesPerPage) - $imagesPerPage; //Now start looping for($i = $from; $i < ($from + $imagesPerPage); $i++){ //We need to make sure that its within the range of totalImages. if($i < $totalImages){ //Now we can display the image! echo "<img src='{$images[$i]}' alt='{$images[$i]}' />"; } } //Now to display the page numbers! for($p = 1; $p <= $totalPages; $p++){ if($p == $page){ $tmp_pages[] = "<strong>{$p}</strong>"; }else{ $tmp_pages[] = "<a href='?page={$p}'>{$p}</a>"; } } //Now display pages, seperated by a hyphon. echo "<br />" . implode(" - ", $tmp_pages); ?> Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670765 Share on other sites More sharing options...
HerrPNut Posted October 21, 2008 Author Share Posted October 21, 2008 it isn't hard coded: <?php if(!empty($_GET["evenement"])){ $evenement = $_GET["evenement"]; $naam = $_GET["naam"]; echo "<h2>".$naam."</h2>"; if($handle = opendir("pics/".$evenement)) { while(($read = readdir($handle)) !== false) { if ($read != "." && $read != ".."){ echo "<div class=\"img\">"; echo "<a href=\"pics/".$evenement."/".$read."\" rel=\"lightbox[".$evenement."]\"><img src =\"pics/".$evenement."/".$read."\" border = \"0\"/ width=\"110\" height=\"90\" /></a>"; ..... ?> Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670777 Share on other sites More sharing options...
JasonLewis Posted October 21, 2008 Share Posted October 21, 2008 Check the script I posted. It should do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670779 Share on other sites More sharing options...
HerrPNut Posted October 21, 2008 Author Share Posted October 21, 2008 Check the script I posted. It should do what you want. ok, if i say: show 9 images, the script shows 9 images and then... if i click on "2" for second page, he doens't show me the rest of the images (in total there are 12, so there should be 3 more images) Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670791 Share on other sites More sharing options...
HerrPNut Posted October 21, 2008 Author Share Posted October 21, 2008 nevermind, problem solved Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670805 Share on other sites More sharing options...
R4nk3d Posted October 21, 2008 Share Posted October 21, 2008 Just use= if(isset($_GET['page'])) { include("pages/$_GET "); } Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670820 Share on other sites More sharing options...
discomatt Posted October 21, 2008 Share Posted October 21, 2008 if(isset($_GET['page'])) { include("pages/$_GET "); } Please don't ever use that line of code T_T page.php?page=../../../below/doc/root/ Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-670867 Share on other sites More sharing options...
R4nk3d Posted October 21, 2008 Share Posted October 21, 2008 if(isset($_GET['page'])) { include("pages/$_GET Please don't ever use that line of code T_T page.php?page=../../../below/doc/root/ "); } hmm. never thought of that. XD sorry. Quote Link to comment https://forums.phpfreaks.com/topic/129381-pagination-without-sql/#findComment-671263 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.