reorder database row output
Posted: Thu Nov 03, 2011 12:34 am
Hi,
I have a very simple mysql database with a few php/html forms to add, update and delete entries. I've added a field called sort_order (someone told me that it is a very bad idea to reorder the actual data in the database) and manually punched in numbers representing the order in which the rows in the database should be displayed (in an html page, or as xml)
Now I want to have some php to allow the user move an entry up or down by incrementing or decrementing the sort_order field. I assume this means iterating through the whole database and rewriting the sort_order field. I need some help figuring out how to go about that.
Also, I tried to make the sort_order field "unique" or an "index" but PhpMyAdmin gives me an error:
[text]
Keyname Type Cardinality Action Field
PRIMARY PRIMARY 15 Edit Drop id
id UNIQUE 15 Edit Drop id
sort_index UNIQUE 15 Edit Drop sort_index
The following indexes appear to be equal and one of them should be removed: PRIMARY, id[/text]
I have a very simple mysql database with a few php/html forms to add, update and delete entries. I've added a field called sort_order (someone told me that it is a very bad idea to reorder the actual data in the database) and manually punched in numbers representing the order in which the rows in the database should be displayed (in an html page, or as xml)
Now I want to have some php to allow the user move an entry up or down by incrementing or decrementing the sort_order field. I assume this means iterating through the whole database and rewriting the sort_order field. I need some help figuring out how to go about that.
Also, I tried to make the sort_order field "unique" or an "index" but PhpMyAdmin gives me an error:
[text]
Keyname Type Cardinality Action Field
PRIMARY PRIMARY 15 Edit Drop id
id UNIQUE 15 Edit Drop id
sort_index UNIQUE 15 Edit Drop sort_index
The following indexes appear to be equal and one of them should be removed: PRIMARY, id[/text]