vendredi 4 mars 2016

Using php, loop and update certain records

Question

I have to award my members with some bonuses on completion of certain tasks.
If they have achieved task1 , new task will be task2
If they have achieved task2 , new task will be task3
If they have achieved task3 , new task will be task4
If they have achieved task4 , new task will be task5

Database

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

My Code:

for ($i=0;$i<=count($offername);$i++) {
    //check for existing bonuses first.  //code omitted

    //####if Its 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  2nd  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);
            }
        }
    }
}

I have already claimed 1st bonus for offer1 == offername[0].
I have tested for $offercurrent[0] , it does not work for ($member['count'] == 1 ) and so on.

Problem


All the values remain same for ($member['count'] == 0 ) and does not change with the count.

Aucun commentaire:

Enregistrer un commentaire