从一个表中选择一系列 id 然后将它们放入事务循环以一次处理更新一条记录的最佳方法是什么?
$result = mysql_query('SELECT p_code FROM replenishment ');
$ids = array();
while ($p_code = mysql_fetch_row($result)) {
$ids[] = $p_code[0];
foreach($ids as $p_code) {
mysql_query('SELECT @A:=replenishment.p_code,@B:=replenishment.model
from replenishment
left join replenishment1 on replenishment1.p_code = replenishment.p_code
where replenishment.branch=10
and replenishment.p_code=$p_code
and replenishment.stock < min
and replenishment1.stock > 0
group by replenishment.p_code');
mysql_query('UPDATE replenishment1
SET stock = (stock - @B), B5=(b5+@B) WHERE @A = replenishment1.p_code
and replenishment1.stock >= @B');
$row = mysql_fetch_assoc();
}
}