Search the Community
Showing results for tags 'pagination php'.
-
So i have the readdir() and a while loop to loop through the contents like this <?php $directory = 'games'; $row=0; if ($handle = opendir($directory.'/')) { echo '<table border="1">'; while ($cat = readdir($handle)) { if ($cat!='.'&&$cat!='..'&&$cat!='index.php') { if($row==0) echo '<tr>'; echo '<td align="center"><a href="'.$directory.'/'.$cat.'" style="text-decoration:none"><img src="'.$directory.'/'.$cat.'/image.php" style="display:block" />'.str_replace('_', ' ', $cat).'</a></td>'; if($row==5) { echo '</tr>'; $row = -1; } $row++; } } echo '</table>'; } ?> It also displays a table with a new row at every three columns of data The following script is a bit harder to handle for me and its like this $dir = "/directory_name"; // Create $files array and populate with files from $dir $files = array(); //if (is_dir($dir)) { // if ($dh = opendir($dir)) { // while (($file = readdir($dh)) !== false) { // if($file != "." && $file != ".."){ array_push($files,$file); //here goes the code above i think? // } // } // closedir($dh); //} //} // Set up some paging info $page_size=10; $total_pages = ceil(count($files) / $page_size); // Get currently selected page, if not selected use 1 if too high use last page if(isset($_GET['p'])){ $current_page = $_GET['p']; if($current_page > $total_pages){ $current_page = $total_pages; } } else { $current_page=1; } // do some math to determine starting array index to use for the current page $start = $current_page * $page_size - $page_size; print "File Listing for $dir<br>Page $current_page of $total_pages<br><br>"; // Print files for current page for($i=$start;$i<$start + $page_size;$i++){ print "$files[$i]<br>"; } // Print links for pages for($j=0;$j<$total_pages;$j++){ $p = $j+1; print "<a href='index.php?p=$p'>$p</a> | "; } I want to integrate the first script into the second if that's possible Thanks!