peuge Posted July 28, 2008 Share Posted July 28, 2008 Wassup all? I have an image gallery with a thumbnail table to the left side of the large picture. The pictures are dumped in their respective category folder and there is a category table on the right of the large picture. All works well, but now I want to be able to add more pictures and need 1,2,3,4 etc for the next page so it does not display all the thumbs. My problem now is that I want to display 10 pictures for each thumbnail page. So far I have this function display_thumbs($images,$cat,$big,$page){ $cols = 2; $page_num=$page; $amnt = ($page*10); $i=-1; if ($handle = opendir($images.$cat)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($big,"/") && $i >= ($amnt-9) && $i <= $amnt) { $files[] = $file; } $i++; } closedir($handle); } $colCtr = 0; echo '<table id="thumbstable"><tr>'; foreach($files as $file) { There is more to the function but that part works. Right now I am only getting it to display about 9 pics on the first page, this then goes to ten, then eleven etc for each next page. I have a whole lot of different combinations of $i etc but cant seem to get it. $images,$cat,$big,$page The first three are just the directory names, the last $page is the page number selected (which starts from 1) Any help is much appreciated. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/116967-creating-page-numbers-for-image-gallery/ Share on other sites More sharing options...
Wolphie Posted July 28, 2008 Share Posted July 28, 2008 This is called pagination. There is a tutorial for it on the main PHP Freaks website. Here http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/116967-creating-page-numbers-for-image-gallery/#findComment-601538 Share on other sites More sharing options...
peuge Posted July 28, 2008 Author Share Posted July 28, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116967-creating-page-numbers-for-image-gallery/#findComment-601542 Share on other sites More sharing options...
peuge Posted July 28, 2008 Author Share Posted July 28, 2008 Looked over that, thanks. But im not using mySQL with this and cannot seem to figure it out? So after some other searhing I found something along the lines of this (which does not work either) $amnt = ($page*10); $limit=0; $i=0; $brk=1; if ($handle = opendir($images.$cat)) { while (false !== ($file = readdir($handle)) && $brk!=0 ) { if ($file != "." && $file != ".." && $file != rtrim($big,"/") && $i > $amnt-10) { $files[] = $file; } $limit++; $i++; if ($limit==10){ $brk=0; } } closedir($handle); } Thanks again EDIT: Sorry the output gives me 7 pics for the first page, but gives an error on the next pages. Warning: Invalid argument supplied for foreach() in functions.php on line 177 That code just displays the pics so its obviously not picking up the pics. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116967-creating-page-numbers-for-image-gallery/#findComment-601565 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.