LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-23-2008, 08:55 AM   #1
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Rep: Reputation: 30
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.

Thanks,
Adam

Last edited by windisch; 10-23-2008 at 08:57 AM.
 
Old 10-24-2008, 06:51 PM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Here's an idea:

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?
 
Old 10-24-2008, 07:01 PM   #3
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
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.
 
Old 10-24-2008, 07:47 PM   #4
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jonaskoelker View Post
Here's an idea:

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.
 
Old 10-24-2008, 07:49 PM   #5
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by abolishtheun View Post
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?
 
Old 10-24-2008, 07:54 PM   #6
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
Maybe look at YUI?:
http://developer.yahoo.com/yui/
http://developer.yahoo.com/yui/dragdrop/

Though I'd still say a dead-simple HTML interface is better than most ajax interfaces out there.
 
Old 10-27-2008, 01:31 PM   #7
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by abolishtheun View Post
Maybe look at YUI?:
http://developer.yahoo.com/yui/
http://developer.yahoo.com/yui/dragdrop/

Though I'd still say a dead-simple HTML interface is better than most ajax interfaces out there.
Thanks, I remeber looking at this in the past. Maybe you are right, I could start with a simple solution.

Do you have an idea on how to do this in a dead simple HTML format?
 
Old 10-27-2008, 02:13 PM   #8
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
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...
 
Old 10-27-2008, 02:16 PM   #9
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by brazilnut View Post
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.
 
Old 11-07-2008, 11:53 AM   #11
windisch
Member
 
Registered: Nov 2004
Location: Gahanna, Ohio, USA
Distribution: Fedora 9
Posts: 158

Original Poster
Rep: Reputation: 30
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.

Last edited by windisch; 11-07-2008 at 12:33 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
wxPython: sortable tree list control? BrianK Programming 1 07-17-2008 04:25 AM
Saving a text file as a variable and reading it every second in java script mrobertson Programming 4 03-26-2007 08:25 PM
Saving m3u list in XMMS Napper Linux - Software 9 02-20-2006 05:48 PM
creating the file list for the .spec files ingerul Linux - Software 0 11-01-2004 03:06 AM
saving list of RPMS DAChristen29 Mandriva 8 08-23-2004 11:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration