上移下移排序处理

SELECT
*
FROM
web_ad
WHERE
1 = 1
AND ad_banner_pages = 7
AND ( find_in_set( 7, sub_channel ) OR find_in_set( 8, sub_channel ) )
ORDER BY
STATUS DESC,
sort DESC
LIMIT $start,
2

$start 表示当前要移动记录当前顺序的第N条记录,移动时参数逻辑

if ($move_type == 2) { $start = $start - 1; }
move_type 1表示下移, 2表示上移

更新逻辑 :

foreach ($list as $key => $unit_sort) { $tmp_key = 0; if ($key == 0) { $tmp_key = 1; } $sort = $list[$tmp_key]['sort']; $id = $unit_sort['id']; $sql = "UPDATE web_ad SET sort = " . $sort . " WHERE id = {$id}"; $ret = $db->query($sql); }