Forum Moderators: coopster

Message Too Old, No Replies

Changing The Order of Database Items

         

txskydiver

8:30 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



I am developing a site for a computer phobic person who wants to update everything himself.

I ran across a need for him to be able to re-order items in the database through a form of some sort. A lot like the Que feature on Netflix if there are any users out there who subscribe.

I am getting wrapped around the axel on this. I know it is simple, but I am having a brain fart as to how best to make it work.

Thanks

jatar_k

9:26 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



to re-order items in the database through a form of some sort

I assume you just mean the output on the screen not the actual order of things in the db, since the order in the db doesn't reall mean anything.

Sorting Rows [mysql.com] (assuming mysql)

txskydiver

9:52 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



I need to change the order in which they display dynamically.

In other words he needs to be able to change:

Item A
Item B
Item C
Item D

To:

Item A
Item D
Item C
Item B

or any varitation thereof, so it is not just order by, but checking the existing order (which I have in a database field called 'order') and updating those that need to change while leaving those that dont alone.

I got into this last night and when I started writing my 3rd level while loop I thought there had to be an easier way.

TM

coopster

10:45 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've had this come up a couple of times, txskydiver. Once, I used a sequencing system where I put the items in an array and resorted based on user changes to the sequence number. It was kind of ugly, but it was what they wanted and it worked. The next time this issue came up, I used javascript. The js was much easier/cleaner to the user. Can you use js?

By the way, Welcome to WebmasterWorld!

txskydiver

11:01 pm on Mar 11, 2004 (gmt 0)

10+ Year Member



I can use JavaScript, but not sure what I would be trying to do..

It's one of those issues that I have stared at for so long that my eyes are crossing and all the solutions are starting to blend together.

coopster

11:45 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Load the data into a <select> list. Then create a couple of buttons, one named UP and one named DOWN. Let your user select an item in the list and when they click UP, use a javascript function to change the value of the item and resort the array. Do the same for DOWN.

You will also need to have the user click a submit button. When they do this, use another js function to select all items in the list and post them to your PHP script which will update the database accordingly.