dimanche 4 novembre 2018

While-Else Condition PHP

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.

  1. I do the select query from database to get all records then get the result in array
  2. I get the total and period from the array
  3. Do the checking, when the $qtyOut > $total, it will loop the statements inside the {}.
  4. 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