Reputation: 2862
I have a table of member in which fields are member_id, referrer_member_id, sales_hold_fund
. I want to check if sales hold fund of a member is > 100 and if it is greater than 100 I want to minus the amount 100 from sales hold fund. So this should go in a loop till the sales hold fund is greater than 100.
Example :
sales hold fund is 300, first it should check if it is greater than 100 if yes it will minus 100 from 300, 200 will be the balance amount, again it will check if balance amount is greater than 100, if yes again it will minus 100 from 200. Now it will check if balance amount is greater than 100 not its not greater so it should stop the loop.
I tried to implement this but this is going in an infinite loop.
$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);
}
}
I want to return the balance amount when it is updated and check if it is greater than 100. Now it is going infinite loop because I am only checking if $fund > 100 which is never getting updated.
How can I do this? Please help.. Thank you..
Can anyone help please? Thank you.
Upvotes: 2
Views: 66
Reputation: 2907
Updated Answer
You are trying to update the $sales_hold_fund
and as per your description your code should be as follows. replace your $fund
with $sales_hold_fund
and perform operation on it. It will be also replace your $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);
}
}
Upvotes: 2
Reputation: 1233
You have to use db functions inside the while loop and sleep connections.
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);
................
............
}
Upvotes: 0