ethan89 Posted September 7, 2010 Share Posted September 7, 2010 I see several great PHP/MySQL paging systems on google, but how can I make a paging system when I'm just showing all images in a directory, not showing all images from a database? I have no idea how I could convert one of those mysql systems to work for my needs. Here is my code: <?php $columns = "4"; $count = "0"; echo '<div style="overflow:auto; width:500px; height:266px;"><table cellpadding="0" cellspacing="10">'; if ($handle = opendir('.')) { while (false !== ($image = readdir($handle))) { if ($image != "." && $image != ".." && $image != "index.php") { if (strlen($image) > 11) { $short = substr($image,0,11); echo '<td align="center"><a href="'.$image.'" title="'.$image.'"><img src="'.$image.'" width="100" height="100"><br><div style="overflow:auto; width:100px;">'.$short.'...</div></a></td>'; } else { echo '<td align="center"><a href="'.$image.'" title="'.$image.'"><img src="'.$image.'" width="100" height="100"><br><div style="overflow:auto; width:100px;">'.$image.'</div></a></td>'; } $count++; if ($count == 4) { echo "</tr><tr>"; $count = 0; } } } closedir($handle); } echo "</table></div>"; ?> This code shows all images in a directory, 4 per row. I'd really appreciate some help with adding a paging feature to this. Thank you so much for the help! Quote Link to comment Share on other sites More sharing options...
hellrisisng Posted September 7, 2010 Share Posted September 7, 2010 The best way I know to do this is to use num_rows to calculate your items in a database then do a simple math to calculate how many to display on each page, you can see by the code ive written for you below, you will need to add to it to make it work like the starting number and amount to limit your resualts by befor you have created a query with a dynamic URL (?page=number). //state how many to display on each page $per_page = 4; //calculating no of pages $pageresult = mysql_query("SELECT * FROM your_table"); $count = mysql_num_rows($pageresult); $pages = ceil($count/$per_page); // display items for this page $start = ($page-1)*$per_page; $result = mysql_query("SELECT * FROM your_table LIMIT $start,$per_page"); Then using CSS to create your page numbers you could try doing somthing with jQuery to funck it up <ul id="pagination"> <? //pagination Numbers for($i=1; $i<=$pages; $i++) {?> <li><a href="your-page.php?page=<? echo $i;?>"><? echo $i;?></a></li> <? }?> </ul> Hope this helps! Quote Link to comment Share on other sites More sharing options...
ethan89 Posted September 7, 2010 Author Share Posted September 7, 2010 Sorry, but I said I don't have a database. Quote Link to comment Share on other sites More sharing options...
hellrisisng Posted September 7, 2010 Share Posted September 7, 2010 PASS! I dont see why you would not want it in a database it is so much easyer to handle, so I couldent help!! All I can sujest is try implamenting the script i supplyed using the 'for' command after counting the number of files in your directory??? Quote Link to comment Share on other sites More sharing options...
ethan89 Posted September 7, 2010 Author Share Posted September 7, 2010 Still need help Quote Link to comment 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.