How to swap two rows of a table in a database using php

Reply

Join Date: Apr 2008
Posts: 109
Reputation: architact is an unknown quantity at this point 
Solved Threads: 7
architact's Avatar
architact architact is offline Offline
Junior Poster

How to swap two rows of a table in a database using php

 
0
  #1
Aug 18th, 2008
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.
If you think we fight for money and you fight for honor, then remember everyone fights for the thing they don't have...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: How to swap two rows of a table in a database using php

 
1
  #2
Aug 18th, 2008
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.
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 84
Reputation: MVied is an unknown quantity at this point 
Solved Threads: 5
MVied's Avatar
MVied MVied is offline Offline
Junior Poster in Training

Re: How to swap two rows of a table in a database using php

 
1
  #3
Aug 18th, 2008
Originally Posted by vicky_rawat View Post
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.
Last edited by MVied; Aug 18th, 2008 at 12:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 109
Reputation: architact is an unknown quantity at this point 
Solved Threads: 7
architact's Avatar
architact architact is offline Offline
Junior Poster

Re: How to swap two rows of a table in a database using php

 
0
  #4
Aug 18th, 2008
thanks alot MVied and vicky i will try your methods. thanks
If you think we fight for money and you fight for honor, then remember everyone fights for the thing they don't have...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: How to swap two rows of a table in a database using php

 
0
  #5
Aug 18th, 2008
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.
Last edited by R0bb0b; Aug 18th, 2008 at 2:51 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 1386 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC