StefAbderahim Posted September 11, 2014 Share Posted September 11, 2014 hi every one thanks for this forum i want help please i want add pagination to this script and listed the floder by last modification <table width='100%' border='0'> <?php $gr = "music/Musique-Maghreb/"; $gr="music/$cat/"; $rep=opendir($gr); $c=1; while ($file = readdir($rep)){ if($file != '..' && $file !='.' && $file !=''){ if (file_exists("images/$file.jpg")) { $img="images/$file.jpg"; } else { $img="images/nophoto.jpg"; } if ($c==1) { echo "<tr>"; } ?> <?php echo $file;?> </tr> <TR> <tr> <td> </td> </tr> </tbody> </table><?php if($c==5) { echo "</tr>"; $c=0; } $c++; } } closedir($rep); clearstatcache(); ?> </td> </center></div> </table> Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 11, 2014 Share Posted September 11, 2014 the best method would be to put the information into an array, then use array_slice() to reference a specific 'page' of that information. the array_slice() offset and length parameters function exactly the same as a LIMIT clause in a mysql based pagination query. Quote Link to comment Share on other sites More sharing options...
StefAbderahim Posted September 11, 2014 Author Share Posted September 11, 2014 bro can you give some exemple please how it's work ?? and how i can listed directory by last added Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 12, 2014 Share Posted September 12, 2014 Perhaps the examples here will help: https://www.google.com/search?q=pagination+with+array_slice Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 12, 2014 Share Posted September 12, 2014 assuming you have or have written a database based pagination script, it is doing two things. 1) getting a total count of the number of data items, and 2) retrieving the correct 'page' of data to display. to accomplish pagination for an array of data, you would first get all your data into an array, in the order that you want the data. then, to accomplish item #1, you would use count() on the array of data. to accomplish item #2, you would use array_slice() on the array of data, using the offset and length (number of rows per page) values normally going into the LIMIT clause in a database query as the parameters going into the array_slice() statement. you would then loop over the array of data that the array_slice() statement returned to produce the output on the page. to get your array of data ordered the way you want, you can either use php's usort() or array_multisort() statements. examples of using these are in the php.net documentation and posted all over the web. 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.