Big small problem.
Posted: Sat Aug 26, 2006 12:40 am
Here's the thing. I need to create a sorting script. I need some serious help.
Basically there's a news script that's displayed and I need to add a textbox (it must be a textbox) so that the user is able to sort the news out (with integers, 1 to $counter).
Till here fine, I have the values stored in a MySql db and I can get / update them just fine. The problem is that I have to:
a) Check for double used values and AUTOMATICALLY correct them. Eg: news1 - position7, news6 - position 7 -> would end up position 7 / 8 respectively.
b) Store the new values (or just the changed ones, I can add a hidden field with the old value for comparison) into the db.
I have no idea of how to validate a).
I also thought of a mathematical solution that involved subtracting the old_value from the new_value, if it yields a positive number it changes values of the fields in between and changes the values of all the fields after the old_value. If it yields a negative value, it changes the values after new_value and subtracts a value from old_value+difference.
It's a mess and I have no idea of how to do this.
Many thanks for the help.
Basically there's a news script that's displayed and I need to add a textbox (it must be a textbox) so that the user is able to sort the news out (with integers, 1 to $counter).
Till here fine, I have the values stored in a MySql db and I can get / update them just fine. The problem is that I have to:
a) Check for double used values and AUTOMATICALLY correct them. Eg: news1 - position7, news6 - position 7 -> would end up position 7 / 8 respectively.
b) Store the new values (or just the changed ones, I can add a hidden field with the old value for comparison) into the db.
I have no idea of how to validate a).
I also thought of a mathematical solution that involved subtracting the old_value from the new_value, if it yields a positive number it changes values of the fields in between and changes the values of all the fields after the old_value. If it yields a negative value, it changes the values after new_value and subtracts a value from old_value+difference.
It's a mess and I have no idea of how to do this.
Many thanks for the help.