1

I'm currently doing some mySQL/PHP but i'm stuck with one small problem. If the user deletes lets say id 4, there's gonna be a gap between sorting 3 and 5. So my thinking is that i need to -(minus) all sort numbers after sort 3 with one.

How do i do that in Mysql? :) I thought it would be something like following, but realize it didn't worked.

UPDATE menucard_category_content SET number_value = number_value-1 AFTER number_value=$sortnr

Table layout looks like:

ID - NAME - SORT - IMAGE
1, pizza, 1, url
2, pizza, 2, url
3, pizza, 3, url
4, pizza, 4, url
7, pizza, 5, url
9, pizza, 6, url

Regards, Simon

1 Answer 1

1

You can do it with an UPDATE statement:

UPDATE yourtable
SET sort = sort - 1
WHERE sort > 3
Sign up to request clarification or add additional context in comments.

1 Comment

Off course Mark, why didn't i think doing that solution. I will check it out, and let you know if it works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.