更新mysql表中的字段时遇到问题

时间:2021-04-02 13:19:48

标签: php mysql

我正在获取已占用床位和已获取可用床位的值。现在,我想通过向可用床位添加 1 张床并从占用床位中减去 1 来更新数据库中的这些值。但是在更新这些时,值会更新 2 倍。

例如:占用床位= 1

    available beds= 6 

预期输出:占用床位=0

             available beds=7

实际输出:占用床位=-1

           available beds=8

更新前查询

更新后查询

$q2 = $dbConnection->prepare("SELECT available_beds,occupied_beds from section_master where section_id=3 AND del_flag=0");
           $q2->execute();
 
           $p1=0;
           $p2=0;
           
         if($q2->rowCount())
          {
            while($row21=$q2->fetch())
            {
             
              $points1=$row21["occupied_beds"];
              $points2=$row21["available_beds"];
              
              
              $qry_res2 = $dbConnection->prepare("UPDATE section_master SET occupied_beds='$points1'-1 , available_beds ='$points2'+1  where del_flag=0  AND section_id=3");  
             $qry_res2->execute();
  
            }
        }

0 个答案:

没有答案
相关问题