I manually move forward the article sort, but the SQL statement seems to have no effect, which helps to see, I really do not see
/* Move forward */if ($result = = ' up ') {$sql 0= $db->query ("Select Sort from". $db->table (' product '). "Where id= ' $id '"); $row =$ Db->fetch_array ($sql 0); if (! $row) {$oldpx = 1;} else{$oldpx = $row [' Sort '],} if ($oldpx >1) {$db->query ("Update". $db->table (' product '). "Set sort=sort+1 where Sort= ". $OLDPX-1); $db->query ("Update". $db->table (' product '). "Set sort=sort-1 where id=". $id); } header ("location:product_list.php\n"); Exit;} /* Move */if ($result = = ' down ') {$sql 1= $db->query ("Select Sort from". $db->table (' product '). "Where id= ' $id '"); $row = $db->fetch_array ($sql 1); if (! $row) {$oldpx = 9999; }else{$oldpx = $row [' sort ']; $sql 2= $db->query ("Select Sort from". $db the->table (' product '). "ORDER BY sort desc LIMIT 1"); $rows = $db->fetch_array ($sql 2); if (! $rows) {$maxpx = 9999; }else{$maxpx = $rows [' sort ']; if ($oldpx < $maxpx) {$db->query ("Update". $db->table (' product '). "Set sort=sort-1 where sort=". $OLDPX + 1); $db->query ("Update". $db->table (' prodUCT '). "Set sort=sort+1 where id=". $id); } header ("location:product_list.php\n"); Exit;}
Reply to discussion (solution)
Whether the article sort is not continuous, just move forward to say you take sort-1 as the tuning to modify it may not be modified to the database record, and then even if the current sort+1 may not be larger than the next article sort
/* Move forward */if ($result = = ' up ') {$sql 0= $db->query ("Select Sort from". $db->table (' product '). "Where id= ' $id '"); $row =$ Db->fetch_array ($sql 0); if (! $row) {$oldpx = 1;} else{$oldpx = $row [' Sort '],} if ($oldpx >1) {$db->query ("Update". $db->table (' product '). "Set sort=sort+1 where Sort= ". $OLDPX-1); $db->query ("Update". $db->table (' product '). "Set sort=sort-1 where id=". $id); } header ("location:product_list.php\n"); Exit;} /* Move */if ($result = = ' down ') {$sql 1= $db->query ("Select Sort from". $db->table (' product '). "Where id= ' $id '"); $row = $db->fetch_array ($sql 1); if (! $row) {$oldpx = 9999; }else{$oldpx = $row [' sort ']; $sql 2= $db->query ("Select Sort from". $db the->table (' product '). "ORDER BY sort desc LIMIT 1"); $rows = $db->fetch_array ($sql 2); if (! $rows) {$maxpx = 9999; }else{$maxpx = $rows [' sort ']; if ($oldpx < $maxpx) {$db->query ("Update". $db->table (' product '). "Set sort=sort-1 where sort=". $OLDPX + 1); $db->query ("Update". $db->table (' prodUCT '). "Set sort=sort+1 where id=". $id); } header ("location:product_list.php\n"); Exit;}
Where the red callout is changed to where Id= ' ". $id." ' ");
if ($_request["action"] = = "Up") {uppx ($_request[' goods_id ']);} ElseIf ($_request["action"] = = "Down") {downpx ($_request[' goods_id ']);} function uppx ($goods _id) {if (! $goods _id) {$goods _id=0;} $sql = $GLOBALS [' DB ']->query ("select px from". $GLOBALS [' DB ']->table (' product '). ' Where id= '. $goods _id); $rs =$ globals[' db ']->fetch_array ($sql), if (! $rs) {$oldpx = 1;} else{$oldpx = $rs [' px '];} if ($oldpx >1) {$oldpx = $oldpx-1; $GLOBALS [' DB ']->query ("Update". $GLOBALS [' DB ']->table (' product '). "Set px= px+1 where px= ". $oldpx); $GLOBALS [' DB ']->query ("Update". $GLOBALS [' DB ']->table (' product '). "Set px=px-1 where id=". $goods _id);} Header ("Location:product_list.php"); exit;} function downpx ($goods _id) {if (! $goods _id) {$goods _id=0;} $sql = $GLOBALS [' DB ']->query ("select px from". $GLOBALS [' DB ']->table (' product '). ' Where id= '. $goods _id); $rs =$ globals[' db ']->fetch_array ($sql), if (! $rs) {$oldpx = 1;} else{$oldpx = $rs [' px '];} If $oldpx=1 words $sql 1= $GLOBALS [' DB ']->query ("select * from". $GLOBALs[' db ']->table (' product '). "ORDER BY px desc LIMIT 1"), $row = $GLOBALS [' db ']->fetch_array ($sql 1); if (! $row) {$ maxpx=999;} else{$maxpx = $row [' px '];} So the largest $maxpx=4 if ($oldpx < $maxpx) {$oldpx = $oldpx +1; $GLOBALS [' DB ']->query ("Update". $GLOBALS [' DB ']-> Table (' Product '). "Set px=px-1 where px=". $oldpx); $GLOBALS [' DB ']->query ("Update". $GLOBALS [' DB ']->table (' product '). "Set px=px+1 where id=". $goods _id);} Header ("Location:product_list.php"); exit;}
According to your code, I'm going to show you the whole time.