while(true)
{
if($total>0)
{
$sql_select=" select * from ot_balance where user_id=".$user_id." and ot_balance>0 order by last desc, hr_datetime asc limit 1";
$this->db->query($sql_select,0,-1);
if($record=$this->db->nextRecord())
{
$ot_balance=$record["ot_balance"];
}
if($ot_balance>=$total)
{
$main = array($total,$user_id);
$sql="update ot_balance set ot_used=ot_used+?, ot_balance=ot_to_used-ot_used-ot_cancelled where user_id=? and ot_balance>0 order by last desc, hr_datetime asc limit 1 ";
$ret = $this->db->execute($sql,$main);
$total=0;
}
else
{
$total=$total-$ot_balance;
}
}
else break;
}
这就是全部的代码呀。
{
if($total>0)
{
$sql_select=" select * from ot_balance where user_id=".$user_id." and ot_balance>0 order by last desc, hr_datetime asc limit 1";
$this->db->query($sql_select,0,-1);
if($record=$this->db->nextRecord())
{
$ot_balance=$record["ot_balance"];
}
if($ot_balance>=$total)
{
$main = array($total,$user_id);
$sql="update ot_balance set ot_used=ot_used+?, ot_balance=ot_to_used-ot_used-ot_cancelled where user_id=? and ot_balance>0 order by last desc, hr_datetime asc limit 1 ";
$ret = $this->db->execute($sql,$main);
$total=0;
}
else
{
$total=$total-$ot_balance;
}
}
else break;
}
这就是全部的代码呀。
$sql_select=" select * from ot_balance where user_id=".$user_id." and ot_balance>0 order by last desc, hr_datetime asc limit 1";
$this->db->query($sql_select,0,-1);
if($record=$this->db->nextRecord())
{
$ot_balance=$record["ot_balance"];
}
if($ot_balance>=$total)
{
$main = array($total,$user_id);
$sql="update ot_balance set ot_used=ot_used+?, ot_balance=ot_to_used-ot_used-ot_cancelled where user_id=? and ot_balance>0 order by last desc, hr_datetime asc limit 1 ";
$ret = $this->db->execute($sql,$main);
$total=0;
}
else
{
$total=$total-$ot_balance;
}
}while($total)
{
$main = array($total,$user_id);
$sql="update ot_balance set ot_used=ot_used+?, ot_balance=ot_to_used-ot_used-ot_cancelled where user_id=? and ot_balance>0 order by last desc, hr_datetime asc limit 1 ";
$ret = $this->db->execute($sql,$main);
$total=0; <== 只要执行一次,就把循环条件破坏了
}
是else 也要写update 语句
谢谢大家。
给分了。。