0

Hello, I am creating a site (for practice). It is a site that works like the '9gag.com' where users can see images stored on the page.

So far, I have successfully retrieved and posted image files from the server but I wanted to put on a limit on how many images will be echoed outside.

I have made the condition that when the number of images arrives to 5 it prints out a next button -->> reloades the page -->> then (SUPPOSES TO) continue reading the next images and prints them. So the output would be 5 images per page.

------The problem is that, I can't think of a best approach for the script to read the next file images STARTING FROM the PREVIOUS echoed file ONCE I CLICK THE NEXT BUTTON-------

This is the code that I come up with so far

<?php
			include 'thumbs.php';
			function createGallery($pathToThumbs)
			{
				$dir=opendir($pathToThumbs);
				$count=1;
				while(($fname=readdir($dir))!==false && $count<=7)
				{
					$path=$pathToThumbs.$fname;
					
					if($fname!='.' && $fname!='..')
					{
						echo "<hr>";
						echo "<img src='$path'>";
						if($count==7)
							echo "<button onClick='createGallery'>next</button>"; 
					}
					$count++;
				}
				closedir($dir);
			}
			createGallery("Thumbs/");
		?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by iamthwee
0

Personally, I'd use javascript for this.On first page load get php to dump all images into js array.
Using the js array and a counter, print 5 images to a div and increment the counter by 5. On button click, use the counter to retrieve the next 5 (overwrite the div contents) and increment counter by 5 again... etc... etc.

This means you don't have to involve the php/server.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.