rem Posted August 1, 2006 Share Posted August 1, 2006 Dear all,I'm trying to develop a small photo gallery in PHP, without using MySQL. The images are taken from within a folder then displayed on the front end. This is something I already managed to achieve and I'm very pleased by the results but the downside is when have large amounts of pictures within the base folder... My page is loaded with tones of thumbs and have to scroll miles to get through it. Could you point me through an easy method of somehow paginating the results and organize them a bit?Thanks a lot!Regards,Rem. Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/ Share on other sites More sharing options...
SharkBait Posted August 1, 2006 Share Posted August 1, 2006 I suppose depending on how you name your photos in the folder.. if you were to do them by numbers and only select 1 to 10 (or whatever) in your loop when you go through the folder, and then if they click on a link it will show 11 to 20?Code wise, I'm not sure. I am sure it can be done though but it would be having to control the loop that loads the contents of the folder and only displaying the amount you want.Get the total amount of items in the directory. Then divide that by how many you want per page. Keep a variable of what page the user is on. If you take a peek at the tutorials on the PHP/MySQL pagnation here in PHPFreaks I'm sure it can be modified to work with folders and files instead of a database :) Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67052 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 thanks for the reply...the images are by names. the name is uppercased and the .ext is dropped.i already looked over the pagination tutorials here but don't have a clue how to work with files within a folder :Dthanks again anyway, I'll try dig some other resources as well... Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67058 Share on other sites More sharing options...
Buyocat Posted August 1, 2006 Share Posted August 1, 2006 How are you pulling the image files onto the html page? I suspect you are using a loop of some sort. If that is the case then you might just amend the loop so it just pulls 10 images, and sets the 11th as a "next" link with the image title in the url. Then when clicked the page would look for the image title in the file directory and would pick ten more photos starting from that photo. Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67125 Share on other sites More sharing options...
gerkintrigg Posted August 1, 2006 Share Posted August 1, 2006 yeah something like:$a=0;while (($a<=10)&&(there are images in the folder)){$a++;grab an image & print to screen;} Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67133 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 thanks a lot guys... really apreciate it :)i'll give that a try! is so cool to have some stuff to get me started... Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67136 Share on other sites More sharing options...
HeyRay2 Posted August 1, 2006 Share Posted August 1, 2006 A lot of the information you get from the MySQL pagination tutorials around the web will still apply. Your source of data only differs. You'll still calculate how many results you have in total, how many you want to print out on each page, and you want to provide links to the other results.I would highly recommend reading some of those tutorials to get started, negating anything that is database related and replacing it with file functions.Here is a good one to start with: [url=http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php]http://www.phpfreaks.com/tutorial_cat/25/Page-Number--Pagination.php[/url] Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67170 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 thanks a lot, any resource is welcomed. next time, if i'll be able to output my gallery, i will not bother you guys anymore, instead maybe i'll be able to help other php newbies like i am now :) Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67202 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 unfortunately i'm kinda forced to come back here guys... the tutorial HeyRay2 pointed me to was great, helped me to understand the pagination process but still, even I managed to get this done with, I'm stuck to the fetching images from x to y stuff from within the folder.here's my code, could you give me a hint, pretty please?thanks a mil![code]<?php$dir = 'home/rem/www/images';$files = @scandir($dir);$num_of_files = count($files) - 2;if(!isset($_GET['page'])){ $page = 1;} else { $page = $_GET['page'];} $max_results = 8;$from = (($page * $max_results) - $max_results); if ($handle = opendir($dir)){ echo "<div id='gallery'>\n\n"; while (false !== ($file = readdir($handle))) // this is where i got stuck and can't figure it out... :( { if ($file != "." && $file != "..") { echo "<div class='tile'><img src='images/" . $file . "' border='0' width='80' height='80' />\n"; $title = str_replace('.jpg','',$file); $title = strtoupper(str_replace('_',' ',$title)); echo "<span>" . $title . "</span>\n</div>\n\n"; } } echo "<br clear='all' />\n\n</div>";}$total_pages = ceil($num_of_files/$max_results);echo "<div style='padding: 5px; margin: 5px;'>";if($page > 1){ $prev = ($page - 1); echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $prev . "'>«Prev</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i) { echo $i . " " ; } else { echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $i . "'>" . $i . "</a> "; }}if($page < $total_pages){ $next = ($page + 1); echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $next . "'>Next»</a>";} echo "</div>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67310 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 i got it, i got it!!!! :)[code]<?php $max_results = 3;$from = (($page * $max_results) - $max_results); $to = $from + $max_results;$x = -1; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $from < $x && $x <= $to) { echo "<div class='tile'><img src='images/" . $file . "' border='0' width='80' height='80' />\n"; $title = str_replace('.jpg','',$file); $title = strtoupper(str_replace('_',' ',$title)); echo "<span>" . $x . "-" . $title . "</span>\n</div>\n\n"; } $x++; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67339 Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 glad that you got it :) may i suggest getting the filenames into an array with scandir, and then loop through the appropriate index of that array? Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67363 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 [quote author=ryanlwh link=topic=102578.msg407586#msg407586 date=1154468379]glad that you got it :) may i suggest getting the filenames into an array with scandir, and then loop through the appropriate index of that array?[/quote]i think I'll have to use other function than scandire since my host is still using php4 (just realised it's a php5 function) ...so, I'll have to store them into an array anyhow :)and how should i "loop through the appropiate index of that array", anyway? :) ??? Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67370 Share on other sites More sharing options...
ryanlwh Posted August 1, 2006 Share Posted August 1, 2006 something like this.[code]for($i=10;$i<21;$i++){ echo $array[$i];}[/code]or take a look at array_chunk or array_slice Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67405 Share on other sites More sharing options...
rem Posted August 1, 2006 Author Share Posted August 1, 2006 thanks a lot guys!!! your resources and directions had been very helpful!!i managed to fire up my own gallery :) from now on... all i gotta do is tweak it here and there and imporve it!best wishes! :)P.S. please consider MoneyBookers for donations too. Where I come from, PayPal doesn't work... Link to comment https://forums.phpfreaks.com/topic/16211-no-mysql-pagination-question/#findComment-67414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.