Page 1 of 1

Big small problem.

Posted: Sat Aug 26, 2006 12:40 am
by deleet
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.

Posted: Sat Aug 26, 2006 12:46 am
by William
So basically you you want:

Code: Select all

NAME         POSITION
News Article1 [__1__]
News Article2 [__2__]
News Article3 [__3__]
News Article4 [__4__]
News Article5 [__5__]
News Article6 [__6__]
News Article7 [__7__]
News Article8 [__8__]
And so on, so if you changed these values:

Code: Select all

NAME         POSITION
News Article1 [__1__]
News Article2 [__7__]
News Article3 [__3__]
News Article4 [__4__]
News Article5 [__3__]
News Article6 [__6__]
News Article7 [__7__]
News Article8 [__8__]
Then you press update, it would make the listing:

Code: Select all

NAME         POSITION
News Article1 [__1__]
News Article3 [__2__]
News Article5 [__3__]
News Article4 [__4__]
News Article6 [__5__]
News Article2 [__6__]
News Article7 [__7__]
News Article8 [__8__]
Did I get that right?

Posted: Sat Aug 26, 2006 12:48 am
by deleet
Yes, that's correct. But how to change the values automatically is out of my reach.

Posted: Sat Aug 26, 2006 12:59 pm
by deleet
*bump* Can anyone help?

Posted: Sat Aug 26, 2006 1:04 pm
by RobertGonzalez
Maybe try sorting the array instead of in the database.

Posted: Sat Aug 26, 2006 1:13 pm
by deleet
That was my original idea but how can I check for duplicates and automatically correct them ( the php function array_unique doesn't work since it returns a changed array ) ?

Posted: Sat Aug 26, 2006 1:29 pm
by RobertGonzalez
There are a bunch of array functins to choose from. Read the array section of the PHP manual for a list of array functions.

Posted: Sat Aug 26, 2006 2:28 pm
by feyd
deleet, you waited just over 12 hours to bump your thread. This is against forum rules. Do not do it again.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not recieve a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.