Hello I have designed a website in which users can create their account and then add or delete their likings, favoorite songs, what i want is that i want them to be able to arrange their likings by moving up and down. for this i need a procedure for swapping the two rows of table so that they can arrange their liking and songs. Please help me, if you have any other idea please share with me.

Thanks in advance.

Hi,

The easiest way that I can think of is:

Create the table dynamically and then when you move up and down, swap the table rows using javascript.

commented: Nice way to do this. +1

Hi,

The easiest way that I can think of is:

Create the table dynamically and then when you move up and down, swap the table rows using javascript.

Certainly the fancy way would be to use something like the Mootools Sortables class to sort a list. You could combine that with some type of server-side language to have it update when they click an Apply button, or even have it update the database every time they move something.

Addionitally you're going to need a column in your database named "Order" or something. I assume that your "Likings" table has the columns song_id, user_id. Add to that an order column and when they move the songs to different positions, just update the row.

If your database is arranged differently, you can still use my method. Just add an order column to your table.

commented: Very detailed answer. Gave very good suggestion +1

thanks alot MVied and vicky i will try your methods. thanks

One of the things that I have done in the past(some would prefer not to because it will change the primary keys) is to delete the values in the table pertaining to that user and then add the values as if it was the first time. This will readjust the order naturally and save the overhead but your primary keys will get high, but big deal right? This option will only work if you don't have foreign keys referencing these primary keys since the primary keys will change.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.