我有一个成员表,其中的字段为member_id, referrer_member_id, sales_hold_fund
。我想检查会员的销售持有资金是否> 100,如果它大于100,我想从销售持有基金减去100。所以这应该是一个循环,直到销售持有基金大于100。
示例:
销售持有基金是300,首先应该检查它是否大于 100如果是,它将从300减去100,200将是余额, 如果是的话,它会检查余额是否大于100 再次它将从200减去100.现在它将检查余额金额 大于100而不是不大于它应该停止循环。
我试图实现这个,但这是一个无限循环。
$stmt = $dbConnection->prepare("select Member.sales_hold_fund,Member.referrer_member_id from Member where member_id=?");
$stmt->execute(array($member_id));
$memberC = $stmt->fetch(PDO::FETCH_ASSOC);
$fund = $memberC['sales_hold_fund'];
while($fund > 100)
{
$balance_amount = $sales_hold_fund - 100;
echo $balance_amount;
$this->updateSalesHoldFund($member_id,$balance_amount);
$profit_sharing = 0.20 * $amount;
$referrer_fees = 0.10 * $amount;
if(!empty($referrer_member_id))
{
// $this->createHundredId($date_of_purchase,$referrer_member_id,$profit_sharing,$referrer_fees,$member_id,$referrer_member_id1);
}
else if (!empty($referrer_member_id1))
{
// $this->createHundredId($date_of_purchase,$referrer_member_id,$profit_sharing,$referrer_fees,$member_id,$referrer_member_id1);
}
else{
// $this->createHundredId($date_of_purchase,$referrer_member_id,$profit_sharing,$referrer_fees,$member_id,$referrer_member_id1);
}
}
我想在更新时返回余额,并检查它是否大于100.现在它将无限循环,因为我只检查$ fund> 100永远不会更新。
我该怎么做?请帮忙......谢谢..
有人可以帮忙吗?谢谢。
答案 0 :(得分:2)
更新了答案
您正在尝试更新$sales_hold_fund
,根据您的说明,您的代码应如下所示。将$fund
替换为$sales_hold_fund
并对其执行操作。它也将替换您的$balance_amount
。
$stmt = $dbConnection->prepare("select Member.sales_hold_fund,Member.referrer_member_id from Member where member_id=?");
$stmt->execute(array($member_id));
$memberC = $stmt->fetch(PDO::FETCH_ASSOC);
$sales_hold_fund = $memberC['sales_hold_fund'];
while($sales_hold_fund > 100)
{
$sales_hold_fund = $sales_hold_fund - 100;
echo $sales_hold_fund;
$this->updateSalesHoldFund($member_id,$sales_hold_fund);
$profit_sharing = 0.20 * $amount;
$referrer_fees = 0.10 * $amount;
if(!empty($referrer_member_id))
{
// $this->createHundredId($date_of_purchase,$referrer_member_id,$profit_sharing,$referrer_fees,$member_id,$referrer_member_id1);
}
else if (!empty($referrer_member_id1))
{
// $this->createHundredId($date_of_purchase,$referrer_member_id,$profit_sharing,$referrer_fees,$member_id,$referrer_member_id1);
}
else{
// $this->createHundredId($date_of_purchase,$referrer_member_id,$profit_sharing,$referrer_fees,$member_id,$referrer_member_id1);
}
}
答案 1 :(得分:0)
您必须在while循环和睡眠连接中使用db函数。
while($fund > 100)
{
$stmt = $dbConnection->prepare("select Member.sales_hold_fund,Member.referrer_member_id from Member where member_id=?");
$stmt->execute(array($member_id));
$memberC = $stmt->fetch(PDO::FETCH_ASSOC);
$fund = $memberC['sales_hold_fund'];
ob_start();
sleep(1);
................
............
}