php产生大于

时间:2018-08-06 13:45:02

标签: php performance

我有一段代码,我曾在几个不同的地方使用过,没有问题,但是它开始产生奇怪且随机的结果,我可以弄清楚这些数字是从哪里来的。什么是使用选择查询来找到数量值(它是表中的整数),然后通过多个if(如果比较)比较该值,否则if里面的语句就是代码(我正在使用php 7)-不是查询问题(我没有抛出任何错误,如果您查看输出,您将看到查询返回的是正确的结果,它要么是格式错误,要么是看不见的错误-对此可能是重复的)

$FindQty = $conn->query("SELECT qty from remainder where isbn13 = '$isbn' and po='$po'");

    $row87 = $FindQty->fetch_assoc();
    $qtyDistribute =  $row87 ['qty'];
     $qtyDistribute2= ($qtyDistribute *1);
while ($qtyDistribute>0){
   if ($bestGuide=='a' && $qtyDistribute>0){ 
if(($qtyDistribute<=$AUsedQty) && ($qtyDistribute>0)){
             $AUsedQty2=$qtyDistribute;
             $AUsedQty4=$qtyDistribute;
             $qtyDistribute2=$qtyDistribute;
            $qtyDistribute=0;
            $AUsedPrice2=0;
            $b1=6;
              $conn->query("Update remainder set AUsedQty='$AUsedQty2' where po='$po' and isbn13='$isbn'");              
        }
        else if($qtyDistribute>$AUsedQty ){
            $AUsedQty4=$qtyDistribute;
          $AUsedQty2=$AUsedQty;
            $qtyDistribute=($qtyDistribute-$AUsedQty);
            $qtyDistribute2=$qtyDistribute;
            $b1=5;
            $conn->query("Update remainder set AUsedQty='$AUsedQty2' where po='$po' and isbn13='$isbn'");
        }


    }
    else{
        $qtyDistribute=0;
        $AUsedQty2=0;
        $AUsedPrice2=0;
        $b1=7;
        $qtyDistribute2=0;
    }


}
else if ($bestGuide=='N' && $qtyDistribute>0){

    if($NPriceMargin>0){
         if(($qtyDistribute<=10) && ($qtyDistribute>0)){
            $NQty=$qtyDistribute;
             $qtyDistribute2=$qtyDistribute;
            $qtyDistribute=0;
            $NPrice2=0;
            $conn->query("Update remainder set NQty='$NQty' where po='$po' and isbn13='$isbn'");
            $a1=5;
        }
        if($qtyDistribute>10){
            $NQty=10;
            $NQty2=$qtyDistribute;
            $NQty3=$qtyDistribute;
            $NQty4=$NQty3-$NCode;
            $Nqty5=$NQty3-10;
            $Nqty6=($NQty3-$Nqty5);
            $conn->query("Update remainder set NQty=10 where po='$po' and isbn13='$isbn'");
            $qtyDistribute3=$qtyDistribute;
            $qtyDistribute=($qtyDistribute-10);
            $qtyDistribute2=$qtyDistribute;
            $NPrice2=0;
            $a1=6;
        }
    }
     else{
        $qtyDistribute=0;
        $NPrice2=0;
        $NQty=0;
        $a1=7;
    }


}

这可以运行从1条记录到100,000条记录的任何地方,我无法解释输出,所以这里是输出示例

  

{“ NPrice2”:0,“ NQty”:0,“ Ncode”:10,“ NPriceMargin”:-2.0375,“ a1”:0,   “ bestGuide”:“ a”,“ bestGuidePrice”:“ 2.06”,“ AUsedQty4”:2,“ AUsedQty”:15,“ AUsedQty2”:2,“ qtyDistribute2”:2,“ b1”:6} INSERTED 2 INTO AUsedQty应该插入15   {“ NPrice2”:0,“ NQty”:0,“ Ncode”:10,“ NPriceMargin”:1.1325,“ a1”:6,“ bestGuide”:“ a”,“ bestGuidePrice”:“ 2.06”,“ AUsedQty4” :18,“ AUsedQty”:25,“ AUsedQty2”:18   qtyDistribute3“:” 28“,” qtyDistribute2“:18,” b1“:6}插入18   AusedQty和10到NQty应该做25 AusedQty和3到NQty

     

{“ NPrice2”:0,“ NQty”:0,“ Ncode”:10,“ NPriceMargin”:-2.1975011174127,“ a1”:0,   “ bestGuide”:“ a”,“ bestGuidePrice”:“ 2.74”,“ AUsedQty4”:15,“ AUsedQty”:15,“ AUsedQty2”:15,“ $ AUsedPrice”:2.74,“ ACode”:“ b”,“ qtyDistribute3“:” 248“,” qtyDistribute2“:15,” b1“:6}   这一次将15插入到AusedQty中

     

{“ NPrice2”:2.5,“ NQty”:0,“ Ncode”:10,“ NPriceMargin”:0.4,“ a1”:0,“ bestGuide”:“ a”,“ bestGuidePrice”:“ 2.74”, “ AUsedQty4”:“ 13”,“ AUsedQty”:15,“ AUsedQty2”:“ 13”,“ $ AUsedPrice”:2.74,“ ACode”:“ b”,“ qtyDistribute3”:“ 248”,“ qtyDistribute2”:“ 13“,” b1“:6},此   一个在AusedQty中插入了13个而不是15个

     

{“ NPrice2”:0,“ NQty”:0,“ Ncode”:10,“ NPriceMargin”:0.5425,“ a1”:6,“ bestGuide”:“ N”,“ bestGuidePrice”:“ 3.13”, “ AUsedQty4”:“ 13”,“ AUsedQty”:0,“ AUsedQty2”:0,“ $ AUsedPrice”:0,“ ACode”:“ p”,“ qtyDistribute3”:“ 23”,“ qtyDistribute2”:13,“ b1“:0,   这应该将10插入NQty中。

如您所见,结果是随机的,我尝试更改$qtyDistribute=intval($qtyDistribute); 也尝试过 get_numeric($qtyDistribute)并给出正确的值

0 个答案:

没有答案