Jump to content

HOw to create pagination for dirctory file listing (No database is used)


pankaj.ghadge

Recommended Posts

Hello, Suppose a directory contain 100 or more file and i want to display only 5 file link in first page. Then i can use pagination to move between these file listing. e.g These are the link to file. when user will click on these link then he/she will see the file contain. file1.txtfile2.txtfile3.txtfile4.txtfile5.txt 1 2 3 4 5 Next I want the solution like this .......Another problem is i want sort the file date wise or by name wiselisting will be like this data of file creation || files2008-11-12 | | file2.txt2008-11-13 | | file1.txt2008-11-14 | | file3.txt2008-11-17 | | file4.txt2008-11-18 | | file5.txt1 2 3 4 5 Nextwhen user will click on date link then listing will be sorted by date . when user will click on file link then listing will be sorted by file name.Is this possible ...........................please tell me the solution.........................................

Link to comment
Share on other sites

usually i would be doing something like thisyou want a...button, link, or whatever they click to submit a value back to the pagegrab the value that is submitted and change your query based on that (make sure you keep that value through your pagination too)$orderby="";if(isset($_GET['order'])){if( $_GET['order'] == date) $orderby = "ORDER BY __date_field__";else $orderby= "ORDER BY __file_name_field__";}query = SELECT * FROM table $orderbyprint out your resultsSince you are not using a databaseinstead of having it change a query like i suggested above you're going to have to change the way you are printing them out...you need to create an ORDER BY for printing out elements in your array of files (I assume it is an array here)

Link to comment
Share on other sites

Read the file list from the directory into an array and then output the array based on a pagination script found on Google.You will need variables for the number of files, the number of files to be listed, the start number for the display of file names, the sort order, etc.It can be done quite simply, but the first thing you need to do is find a pagination script. Then convert it to using the array. Most pagination scripts use a Database results method, but it is certainly do-able from an Array. The server will need to read the list each time the script is accessed, so expect the server Resources to have that demand placed on it, especially for a directory with many files.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...