Okay, I think I'm with you now. If you have
id=1 name=Tennis code=1
id=3 name=Volley code=2
id=4 name= Basket code=3
And you delete id=3, you want to end up with:
id=1 name=Tennis code=1
id=4 name= Basket code=2
With the code field adjusted.
Here's the idea: before deleting the record, find out what its code is:
SELECT code FROM articolo WHERE id=3;
and capture the result in $code - we'll be using later. Then do the delete:
DELETE FROM articolo WHERE id=3.
Now comes the code updating. We want every record with a code greater than the one just deleted to have its code value decreased by one (to fill the gap):
UPDATE articolo SET code=code-1 where code>$code
does this.
Is this what you wanted?