I have an sql table with articles in it. I stored the order of the articles in an INT field in sql.
With an ajax post from the (drag and drop) UI, i got an array with integers (new order).
example:
Old order: 2,1,3,4
New order should be: 2,1,4,3
php:
$i = 1;
foreach ($inputarray as $var) :
if ($i != $var) :
$this->_sqli->query("UPDATE articles
SET artorder=$i WHERE artorder = $var and pagesid = $pagesid");
endif;
$i++;
endforeach;
The problem: when i try to swap elements, they are gonna be the same. So the previous example's output will be: 2,1,4,4 How should i update my sql?