Creating a sortable list reading and saving to a file
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Creating a sortable list reading and saving to a file
I currently have a PHP page that reads from a play list file and shows the order of songs that have been queued up. The data has been pulled into an array. I would like to have the ability to have users change the order on the web page and then save it back to the play list file.
I have tried doing this in the past using some examples on the web, but have not had any luck. I would be happy with an AJAX or non AJAX solution. I would appreciate any help.
Create a bog standard form. For each file in the playlist, create a button [move this file] and an input field [Artist - Title.mp3], that's grayed out. When the user clicks "move this file", all the buttons change label to "move the file here", except for the one that was clicked, which changes to "(don't move file)". Have some javascript that moves the file up (down) by iteratively swapping it with all files above (below) it until hitting the target.
When the user posts the form, you store the result as the new playlist.
Do you think you can run with that?
You said you didn't have any luck. How so? How did the things you try fail?
how about a netflix-queue like interface? where each item has an editable text box to its left-- the user can enter a new numbers and click an "update all" button. of course, you can't expect the user to make perfect rearrangements, so you "clean" the user input server side.
Create a bog standard form. For each file in the playlist, create a button [move this file] and an input field [Artist - Title.mp3], that's grayed out. When the user clicks "move this file", all the buttons change label to "move the file here", except for the one that was clicked, which changes to "(don't move file)". Have some javascript that moves the file up (down) by iteratively swapping it with all files above (below) it until hitting the target.
When the user posts the form, you store the result as the new playlist.
Do you think you can run with that?
You said you didn't have any luck. How so? How did the things you try fail?
Thanks for your response Jonas.
I would like that sort of interface a lot. Unfortunately I'm not sure how to do create a button that does what you are describing. My experience forms is pretty much with text fields. Do you know of any example code that does something like you explained?
What I tried in the past was an AJAX drag and drop form, but they were formatted for reading and saving to a mysql database, and I just couldn't seem to convert the code to read to and from my playlist file.
how about a netflix-queue like interface? where each item has an editable text box to its left-- the user can enter a new numbers and click an "update all" button. of course, you can't expect the user to make perfect rearrangements, so you "clean" the user input server side.
Thanks for your response abolishtesun.
I've thought of that also, I just would like if possible to move to a "prettier" form with either a drag and drop or the way that Jonas described. If I can't manage to do that, I will consider your suggestion. Do you happen to know how to start a form like this?
As abolishtheun stated, put a text box on the side of each entry, in your database call this field weight and as you extract order by it. Any duplicates will still be ordered (probably) by the insertion id (or something else if you specify it). If you wanted, as you printed them out you could rename the weights nicely.
Oh, and when the update button is pressed, update the weights...
As abolishtheun stated, put a text box on the side of each entry, in your database call this field weight and as you extract order by it. Any duplicates will still be ordered (probably) by the insertion id (or something else if you specify it). If you wanted, as you printed them out you could rename the weights nicely.
Oh, and when the update button is pressed, update the weights...
That would work, but I'm reading from and writing to a flat file, not a database.
Its a simple file that just has a filename path on each line.
Ok I've gone the route of a simple HTML form. It currently has a text box next to each song. The name of the field is Order1, Order2, etc, etc. My question is on the page that recieves the post, how do I take into account an unknown number of Order# fields to grab from post?
I was thinking of creating another variable to send with the form that contains the number of lines.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.