I know that my question might be similar with while else statement? PHP. However, that solution doesn't seem to work with my case.
So, in my case is something like this.
- I do the
selectquery from database to get all records then get theresult in array - I get the
totalandperiodfrom the array - Do the checking, when the
$qtyOut > $total, it will loop the statements inside the{}. - This is the problem here, AFTER LOOP ENDS, it should do else statement (call another function).
public function trialOut($id, $qtyOut)
{
$a = $this->uri->segment(3);
$dataset = $this->m1->trial($a);
$i = 0;
$sisa;
$total = $dataset[$i]['total'];
$period = $dataset[$i]['periode'];
if($qtyOut > $total){
while ($qtyOut > $total) {
$qtyOut = $qtyOut - $total;
$this->m1->updateOut2($period, $id);
$i++;
$total = $dataset[$i]['total'];
$period = $dataset[$i]['periode'];
}
} else{ //when while loop ends, i want it to execute the code here
$sisa = $total - $qtyOut;
$this->m1->updateOut1($period, $sisa, $id);
}
}
And I still can't found the proper way to do this, should I use another loop method and how to do that?
Aucun commentaire:
Enregistrer un commentaire