somewon Posted October 13, 2008 Share Posted October 13, 2008 Okay, I'm not sure if this is the right way to do this, or that it's even possible. The situation is that I am making image gallery pages with 100+ links/images each. I want to display about 15-20 per page, and have a small numerical link bar that will let you select between the pages. For example, say I had a page of 100 image links with thumbnails. I don't want to display all of them at the same time, so I'd rather it just show 15 of those to the user at a time, and let them select between pages with a small linkbar that looks like: "Page 1 2 3 4 5 6" having those all as links. I hope this makes sense, because I'm pretty bad at explaining myself sometimes. =p What is the best way to go about this? Would an array work, or is there a better way? The site isn't uber-complicated or anything, so the easiest way to do this is probably best. =p I just want to be able to add/update the galleries all the time and have them separated by pages automatically rather than hard coding them all. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/ Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 That's called pagination. Do you have a database set up with all of these images and stuff, or are you actually doing it by hand? (I hope you aren't) Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/#findComment-663959 Share on other sites More sharing options...
Maq Posted October 13, 2008 Share Posted October 13, 2008 If you use pagination, here's a tutorial, Pagination. Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/#findComment-663962 Share on other sites More sharing options...
somewon Posted October 13, 2008 Author Share Posted October 13, 2008 Well, actually, I'm uploading my images to an image hosting service that automatically generates a list of links to the images in your galleries for you, like: <a href=http://imagehost.com/img.php?id=12345><img src=http://imagehost.com/thumb/12345.jpeg></a> <a href=http://imagehost.com/img.php?id=23456><img src=http://imagehost.com/thumb/23456.jpeg></a> ... etc So they're not really in a database or anything, just a long list of links. I just want to be able to display them in my own simple gallery on my website in a way that's easy for people to browse. Is pagination doable without having a database? Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/#findComment-663970 Share on other sites More sharing options...
fanfavorite Posted October 13, 2008 Share Posted October 13, 2008 The simplest way I think is to just read from a directory. Make a directory called "gallery" or whatever you want and then use opendir, readdir, store them into an array and then sort them. I use _small at the end of each thumbnail to determine that it is the thumbnail. Heres a start: if ($_GET[pg]) { //if pg is passed $curpg = $_GET[pg]; //set var } else { $curpg = 1; //default to page 1 } $dir = $_SERVER['DOCUMENT_ROOT'] . '/gallery'; //gallery directory $dirHandle = opendir($dir); //open directory while ($file = readdir($dirHandle)) { //read directory if(!is_dir($file) AND strpos($file, '_small')>0 ) { //don't read directories or files with _small in the filename $files[] = $file; //array for all the pictures } } closedir($dirHandle); //close directory asort($files); //sort the files $numpics = count($files); //get the number of ipictures $numpages = ceil($numpics/20); //get the number of pages if 20 per page $startpic = $curpg * 20 - 19; // get the picture to start with Then list your pictures how you want using that. Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/#findComment-663972 Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 I'd probably create a file that contains each of your links separated by a newline or something, then read it into an array using file(), if you don't want to use a database or host your own files. Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/#findComment-663973 Share on other sites More sharing options...
somewon Posted October 13, 2008 Author Share Posted October 13, 2008 Ahh, thanks guys. I'll try to do a combo of what you've suggested and see how it works. =p Quote Link to comment https://forums.phpfreaks.com/topic/128203-solved-storingdisplaying-html-links-in-an-array-or-perhaps-a-better-way/#findComment-664058 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.