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/");
		?>

Recommended Answers

All 2 Replies

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.