使用PHP,循环并更新某些记录

时间:2016-03-05 06:26:09

标签: php mysql sql if-statement for-loop

问题

我必须在完成某些任务时给我的会员奖励一些奖励。
如果他们已经完成任务1,新的任务将是任务2
如果他们已经完成了task2,那么新的任务将是task3
如果他们已经完成任务3,新的任务将是任务4
如果他们已经完成任务4,则新任务将是task5

数据库

while($row = mysql_fetch_array($sql))
{
    $offername[] = $row['name'];
    $offertask1[] = $row['task1'];
    $offertask2[] = $row['task2'];
    $offertask3[] = $row['task3'];
    $offertask4[] = $row['task4'];
    $offertask5[] = $row['task5'];
    $offerprize[] = $row['prize'];
    $offercurrent[] = $row['current'];
    $offerpercent[] = $row['percent'];
    $offertask[] = $row['task'];
}

Values:
$offername[]  = (offer1, offer2, offer3 ,offerXX)
$offertask1[] = (100,150,200 ,taskxx)
$offertask2[] = (100,150,200 ,taskxx)
$offertask3[] = (100,150,200 ,taskxx)
$offertask4[] = (100,150,200 ,taskxx)
$offertask5[] = (100,150,200 ,taskxx)
$offerprize[] = (5000,2222,3333 ,taskxx)

$offertask= this will replace it value with $offertask1[]
 ,$offertask2[] to $offertask5[] , depending upon the condition

我的代码

for ($i=0;$i<=count($offername);$i++) {

    // Check for existing bonuses first. // Code omitted

    //#### If it's the first bonus ########
    if ($member['count'] == 0 ) {
        if ($offerprize[$i] != 0) {
            $offertask = array_replace($offertask, $offertask1);
            $per = $offercurrent[$i]/$offertask[$i] * 100;
            $offerpercent[$i] == round($per);
        }
    }

    //### If he has claimed one bonus and this is the second bonus #####
    if ($member['count'] == 1 ) {
        if ($offercurrent[$i] >= $offertask1[$i] AND $offercurrent[$i] < $offertask2[$i]) {
            if ($offerprize[$i] != 0) {
                $offertask = array_replace($offertask, $offertask2);
                $per = $offercurrent[$i]/$offertask[$i] * 100;
                $offerpercent[$i] == round($per);
            }
        }
    }
}

我已经声明了offer1 == offername [0]的第一个奖金。
我测试过$ offercurrent [0]。它不适用于($ member ['count'] == 1)等等。

问题

($ member ['count'] == 0)的所有值都保持不变,并且不随计数而改变。

0 个答案:

没有答案