如何将IF语句放在循环中

时间:2017-05-21 15:14:13

标签: php

好的,所以我有这个循环,如果循环落在某个值上,我想更改值。例如,在下面的代码中,对于Tier2,$ p将等于15。但是当运行脚本没有任何反应时,它只是正常运行并忽略我的if语句。

$get_sponsor = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT sponsor FROM ap_members WHERE id=$affiliate_id"));
$sponsor = $get_sponsor['sponsor'];
for ($loop = 2 ; $loop < $levels; $loop++){ 

    //CHECK FOR AVAILABLE SPONSOR
    if($sponsor!='0'){

        //GET LEVEL PERCENTAGE
        $gp = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM ap_other_commissions WHERE id=1"));
        $p = $gp['tier'.$loop.'']; 
            if($p == 15){ // changes for custom override
                $sc = $tier2_com / 100;
            } else {
                $sc = $p / 100;
            }
        $se = $sale_amount * $sc;

1 个答案:

答案 0 :(得分:0)

   //GET LEVEL PERCENTAGE
                $gp = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM ap_other_commissions WHERE id=1"));
                $p = $gp['tier'.$loop.'']; 
                    if($loop == 2){ // changes for custom override
                        $p = $tier2_com;
                        $sc = $tier2_com / 100;
                    } else {
                        $sc = $p / 100;
                    }
                $se = $sale_amount * $sc;

我发布了我在if语句中缺少$ p以便在数据库中正确更新它。现在都在工作..感谢你们的建议。