Hello!
There is an array of pictures
$usr_imgs = array('1.jpg','3.jpg','8.jpg','9.jpg','11.jpg'); The array is added to the table whose keys are the ord field, and the values are photo_name:
+----+------------+-----+ | id | photo_name | ord | +----+------------+-----+ | 13 | 1.jpg | 0 | | 14 | 3.jpg | 1 | | 15 | 8.jpg | 2 | | 16 | 9.jpg | 3 | | 17 | 11.jpg | 4 | +----+------------+-----+ In the $ usr_imgs array, the user added another image, for example, '5.jpg'. The array now has the following form:
$usr_imgs = array('1.jpg','3.jpg','5.jpg' ,'8.jpg','9.jpg','11.jpg'); The question is, how can a single MySQL query overwrite keys for values that already exist in the table? (or one will fail?)
A new picture 5.jpg add as a new entry with the appropriate key. Those. to get this table:
+----+------------+-----+ | id | photo_name | ord | +----+------------+-----+ | 13 | 1.jpg | 0 | | 14 | 3.jpg | 1 | | 15 | 8.jpg | 3 | | 16 | 9.jpg | 4 | | 17 | 11.jpg | 5 | | 18 | 5.jpg | 2 | +----+------------+-----+
update ord=ord+1 where ord>=2helps - Mike