Welcome Guest, Not a member yet? Register   Sign In
How can i use variable from diffrent foreach to get value by adding 2 variable itself
#3

(This post was last modified: 09-28-2015, 05:51 PM by pdthinh.)

(09-28-2015, 04:44 PM)freddy Wrote: Hello guys, now i have little problem that spend my time not to hard but don't know how to solved this, here is my view






Code:
<?php
foreach ($sum->result() as $row) {  ?>

$untung=$row->jumlah_item;

<?php  }  ?>



<?php
foreach ($sumongkir->result() as $row) {  ?>

$ongkir=($row->total);

<?php  }  ?>


$total=$untung+$ongkir; //it doesn't working, what do i wrong here? please guide me to debug it, thanks

Assume two query result in the same size

PHP Code:
// assume $sum->num_rows() == $sumongkir->num_rows()
for ($i 0$i $sum->num_rows(); ++$i) {
    $untung=$sum->row($i)->jumlah_item;
    $ongkir=$sumongkir->row($i)->total;
    $total+=$untung+$ongkir;    


Not sure I understand your question correctly but I think $total may be an array $total[$i]
Reply


Messages In This Thread
Declare variables outside of loop - by JayAdra - 09-28-2015, 05:18 PM
RE: How can i use variable from diffrent foreach to get value ... - by pdthinh - 09-28-2015, 05:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB