下面是我非常基本的代码。我需要帮助,因为有时我的声明会更新两次。
$queryCS="Select * FROM coin_market_sell";
$resultCS=mysql_query($queryCS);
while($rowCS=mysql_fetch_array($resultCS)){
$cms_id=$rowCS['cms_id'];
$cms_by=$rowCS['cms_by'];
$cms_coin_amount_balance=$rowCS['cms_coin_amount_balance'];
$cms_coin_id=$rowCS['cms_coin_id'];
$wallet_amountnew=0;
$queryCOIN2="Select * FROM wallet WHERE user_id=$cms_by and currency_id=$cms_coin_id";
$resultCOIN2=mysql_query($queryCOIN2);
while($rowCOIN2=mysql_fetch_array($resultCOIN2)){
$wallet_id=$rowCOIN2['wallet_id'];
$wallet_amount=$rowCOIN2['wallet_amount'];
$wallet_amountnew=$wallet_amount+$cms_coin_amount_balance;
}
mysql_query("UPDATE wallet SET wallet_amount='$wallet_amountnew' WHERE wallet_id='$wallet_id'");
mysql_query("DELETE FROM `coin_market_sell` WHERE `coin_market_sell`.`cms_id` = $cms_id");
}
答案 0 :(得分:0)
我不是百分百想要尝试的东西,但是我认为UPDATE
陈述必须在内部循环之内:
$queryCOIN2="Select * FROM wallet WHERE user_id=$cms_by and currency_id=$cms_coin_id";
$resultCOIN2=mysql_query($queryCOIN2);
while($rowCOIN2=mysql_fetch_array($resultCOIN2)){
$wallet_id=$rowCOIN2['wallet_id'];
$wallet_amount=$rowCOIN2['wallet_amount'];
$wallet_amountnew=$wallet_amount+$cms_coin_amount_balance;
mysql_query("UPDATE wallet SET wallet_amount='$wallet_amountnew' WHERE wallet_id='$wallet_id'");
}
顺便说一句:使用过期的mysql_*
API,停止。移至mysqli_*
或PDO