Php 始终将最后一行数据插入数据库(2个变量)

Php 始终将最后一行数据插入数据库(2个变量),php,mysql,sql,function,Php,Mysql,Sql,Function,代码只是不断检索要插入数据库的最后一行。(下图)我选择并删除了USD和CA,当插入DB时,行中的损益和当前价格不匹配 当它应该是1.04930和-0.72时,它显示为98.570和1.17 问题是它一直在while循环中获取最后一行值并插入到DB中。如何修复此问题,使变量从正确的行中检索 While回音环路 while($row = mysql_fetch_assoc($result)){ //Creates a loop to loop through results

代码只是不断检索要插入数据库的最后一行。(下图)我选择并删除了
USD
CA
,当插入DB时,行中的损益和当前价格不匹配

当它应该是1.04930和-0.72时,它显示为98.570和1.17

问题是它一直在while循环中获取最后一行值并插入到DB中。如何修复此问题,使变量从正确的行中检索

While回音环路

    while($row = mysql_fetch_assoc($result)){   //Creates a loop to loop through results
    echo "<tr><td>" . $row['trade_id'] .         
            "</td><td>" . $row['selection'] . 
            "</td><td>" . $row['date'] .
            "</td><td>" . $row['type'] .
            "</td><td>" . $row['size'] .
            "</td><td>" . $row['bidprice'] .
            "</td><td>" . $row['offerprice'] .
            "</td><td>" . $row['stoploss'] .
            "</td><td>" . $row['takeprofit'] .
            "</td><td>" . $closedb . 
            "</td><td>" . $profitandloss . 
            "</td><td><a href ='delete.php?id=".
            $row['trade_id']."'>X</a>
           </td></tr>"; 

    }
 function callvariable($closedb,$profitandloss)
    {
      $variable=array('$closedb','$profitandloss');

    return $variable;
    } 

请给我们看一下您表的模式。了解
close
profitandloss
的字段类型很重要。为了进行调试,您应该将查询字符串打印到屏幕上,以便在运行时查看变量的值。大家好,steven,字段类型是float 19,2,但我认为它是closedb和profitloss,我认为它检索最后一行,因为它是最后一行,也是循环的结尾,但我不知道哪个部分会影响它。
 $var=callvariable($closedb,$profitandloss);

 $mysqli-> query("UPDATE `trade_history1` SET `dateclose` = CURRENT_TIMESTAMP,
                                             `close` = '{$closedb}',
                                             `profitandloss` = '{$profitandloss}'
                                            WHERE `trade_id`= ".$trade_id);