PHP article after the order to move forward, write the statement did not work, do not know what the problem?

Source: Internet
Author: User
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.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.