I want to know how I should go about re-ordering records sent from a db table - but I want to order the data in a custom manner, i.e. allowing a user to change the position of the records.
I have a table (for example sakes lets call this table TABLE1).
TABLE1 has 4 fields:
ID, TITLE, CONTENT [and] VISIBLE. (all these fields are self explanatory - with TITLE and CONTENT being text feilds and VISIBLE being a varchar of either '1' or '0'.)
See, simply adding another field in the table is the way I'm thinking. We'd call this feild 'POSITION'. If I assign an unique value to each record's POSITION feild, then on a click of a button, my script would somehow +1 the POSITION of this record, and -1 the position of the previous record.
I'm sure if I thought long and hard about this, I could probably write a script to reflect this. Trouble is, I think ahead; what happens when a record is DELETED, or a records VISIBLE = 0?!?
I can't think what to do! :scared:
Please help me develop this script! All ideas would be greatly appreciated!
EDIT: PS. I'm not necessarily asking for the entire code to be written, I'm more interested in the logic behind it. I'm seriously perplexed!