TGWSE_GY Posted July 16, 2009 Share Posted July 16, 2009 Hi guys, I am pulling images dynamically from a directory and resizing them with another script. However I am wanting to after say 20 images stop the displaying of images and then provide a next link and pick up where I left off for the next 20 images on the following page and etc. untill I get to the last image. Here is a link to what I am doing: http://www.hmtotc.com/private/george/projects/dandj3/index.php and here is the code for my script that generates the images on the right hand side of the screen. <? include('db_con.php'); //define the path as relative $path = "http://www.hmtotc.com/private/george/projects/dandj3/gallery"; $target = "gallery/"; //using the opendir function $dir_handle = @opendir($path) or die("Unable to open $path"); $count = 0; //echo "Directory Listing of $path<br/>"; echo "<table align=\"center\" cellpadding=\"2\" cellspacing=\"1\"><tr valign=\"bottom\">"; //running the while loop while ($file = readdir($dir_handle)) { //echo "<img src=\"$target$file\" />"; $query = mysql_query("SELECT Votes FROM image_info WHERE ImgName='$file'"); $results = mysql_fetch_assoc($query); $votes = $results['Votes']; if ($file != "." && $file != "..") { echo "<td>"; echo "<a rel=\"lightbox\" href=\"$target$file\" ><img src=\"resize.php?percent=20&img=$target$file\" border=\"0\" /></a>"; echo "<br />"; echo "Votes: $votes"; echo "<br />"; echo "<a href=\"vote.php?id=$file\">VOTE</a>"; echo "</td>"; $count = $count + 1; if ($count == 3) { echo "</tr>"; echo "<tr valign=\"bottom\">"; $count = 0; } } } //closing the directory closedir($dir_handle); if ($count > 3) { echo "</tr>"; echo "</table>"; } elseif ($count == 0) { echo "</table>"; } ?> Any help would be greatly appreciated guys. Thanks in advance George! Quote Link to comment https://forums.phpfreaks.com/topic/166214-solved-dynamicly-creating-multiple-page/ Share on other sites More sharing options...
Bendude14 Posted July 16, 2009 Share Posted July 16, 2009 sounds a bit like your after pagination http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/166214-solved-dynamicly-creating-multiple-page/#findComment-876490 Share on other sites More sharing options...
TGWSE_GY Posted July 16, 2009 Author Share Posted July 16, 2009 Thanks ben, however that tutorial is talking about pulling from a database of information and I am using a directory. Would I have to have a temporary table for this in my db then and use that to process, or could I simply use a cookie to count say 1-20, when the click next on the first page the script looks at a cookie sees that 1-20 has previously been displayed and skips the first 20 images in the directory and displays 21 to 30.... etc. Or am I going to need to create a table a new table for the images all together? Thanks George! Quote Link to comment https://forums.phpfreaks.com/topic/166214-solved-dynamicly-creating-multiple-page/#findComment-876494 Share on other sites More sharing options...
Bendude14 Posted July 16, 2009 Share Posted July 16, 2009 well ideally you want to be just taking 20 images from the directory as you need them otherwise you will be downloading every image everytime... Of course you could implement some sort of cache to speed things up... How many images are we talking maximum? Quote Link to comment https://forums.phpfreaks.com/topic/166214-solved-dynamicly-creating-multiple-page/#findComment-876599 Share on other sites More sharing options...
TGWSE_GY Posted July 17, 2009 Author Share Posted July 17, 2009 Thanks, I got it, what I did was tested the directory against a table in a db and if the file doesn't already have a record it creates one for it with 0 votes. Also have it filtering out the . .. as well. Thanks George! Quote Link to comment https://forums.phpfreaks.com/topic/166214-solved-dynamicly-creating-multiple-page/#findComment-877019 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.